This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes invokeLater is not getting called Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "invokeLater is not getting called" Watch "invokeLater is not getting called" New topic
Author

invokeLater is not getting called

sampath surineni
Greenhorn

Joined: Apr 02, 2012
Posts: 29

Hi

I'm working on an alarm application. I'm using SwingUtilities.invokeLater method to call my UI for snooze function. But when I run it I noticed that SwingUtilities.invokeLater function is not being called. Please help me with this problem

Stevens Miller
Ranch Hand

Joined: Jul 26, 2012
Posts: 523
    
    3

How long are you waiting? Looks like your code calls check if the alarm is in the future (which means you have to wait until the alarm time passes), or it adds a day to the alarm time and then calls check. Unless your alarm time starts more than a day in the past, either situation will have you waiting in check. Since your makeReady method creates a Calendar object with getInstance, and only sets the hour, minute, and second, the alarm time is always set for the current day, so you are always going to end up either waiting for that time today, or waiting for that time tomorrow.

Note that your while loop is totally compute-bound while it waits. That is, at line 54, the loop is going to run over and over, using up as much of your CPU as it can get, until the alarm time comes. That's probably not the approach you want to use.
sampath surineni
Greenhorn

Joined: Apr 02, 2012
Posts: 29

Stevens Miller wrote:How long are you waiting? Looks like your code calls check if the alarm is in the future (which means you have to wait until the alarm time passes), or it adds a day to the alarm time and then calls check. Unless your alarm time starts more than a day in the past, either situation will have you waiting in check. Since your makeReady method creates a Calendar object with getInstance, and only sets the hour, minute, and second, the alarm time is always set for the current day, so you are always going to end up either waiting for that time today, or waiting for that time tomorrow.

Note that your while loop is totally compute-bound while it waits. That is, at line 54, the loop is going to run over and over, using up as much of your CPU as it can get, until the alarm time comes. That's probably not the approach you want to use.


Hi Mr. Stevens Miller. Yes my code calls check if alarm time is for future. I wait till it is the time set by the user. I changed the while statement with advice from other programmers it is now


But it still didn't solve my problem
Stevens Miller
Ranch Hand

Joined: Jul 26, 2012
Posts: 523
    
    3

How long do you wait? Consider adding these lines before your call to Thread.sleep to see what the interval is:

My guess is that you are setting the alarm far enough into the future that you aren't waiting long enough for invokeLater to get called.
 
 
subject: invokeLater is not getting called
 
Similar Threads
Calendar class Regarding...
How to set time 11:00 PM using Date or GregorianCalendar
Calendar returns wrong date?
Converting timezone
I am unable to see the fields inside my frame