Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

invokeLater is not getting called

 
Greenhorn
Posts: 29
Android Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Bartender
Posts: 1464
32
Netbeans IDE C++ Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1464
32
Netbeans IDE C++ Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic