Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9266755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:23:29+00:00 2026-06-18T14:23:29+00:00

I am trying to write a java code that will give an alert at

  • 0

I am trying to write a java code that will give an alert at a specific time of day but I don’t know why I am failing(Please be gentle to my questions as I am totally new to programming). I have this code

    new ScheduledThreadPoolExecutor(1).schedule(new Runnable() {
    public void run() {
        if(Calendar.SECOND==30)
        {
            JOptionPane.showMessageDialog(null, "Hola Amigo");
        }
    }
}, 1, TimeUnit.SECONDS);

Should I try to refresh the page? Please help…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T14:23:30+00:00Added an answer on June 18, 2026 at 2:23 pm

    You are checking that a fixed constant value Calendar.SECOND (13) equals 30. Obviously, this will never be true so the dialog will never appear. You need to check this field in a Calendar instance.

    Also using schedule means that the executor thread is only run once. Use scheduleAtFixedRate.

    Also you would need to call showMessageDialog in the EDT to ensure that the call does not block the Executor Thread.

    ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
    scheduler.scheduleAtFixedRate(new Runnable() {
        public void run() {
            Calendar calendar = Calendar.getInstance();
            int second = calendar.get(Calendar.SECOND);
            if (second == 30) {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        JOptionPane.showMessageDialog(null, "Hola Amigo");
                    }
                });
            }
        }
    }, 1, 1, TimeUnit.SECONDS);
    

    If you want to call the ExecutorService every 30 seconds rather than repeatly checking the current second, you could call

    scheduler.scheduleAtFixedRate(myRunnable, 1, 30, TimeUnit.SECONDS);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What's up y'all, I am trying to write some code in Java that will
I'm trying to write a java code on an Android emulator that will send
I'm trying to write a Java UDF that will rank tuples in a bag
I am trying to write a small Java application that will let me run
I've been trying to write some very fast Java code that has to do
I am trying to write a java program that will allow me to send
For Pi Day, I am trying to write a Java program that tries to
I am trying to write a simple Java Applet/Application that will resize itself depending
I'm trying to write code that will traverse an undirected, unweighted graph. Essentially, the
I'm trying to write a Java program that will run an OpenOffice Macro. I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.