• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

invokeLater is not getting called

 
sampath surineni
Greenhorn
Posts: 29
Android Chrome Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1303
24
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
Android Chrome Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1303
24
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic