• 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 wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Scheduled check ...

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

First of all Hi to everyone, as this is my first post here !

I'm writing (trying) a simple java app that could make a db query, fetch result and display message on the screen ... and do it every 5 min .
I've got everything working except those 5 min ...
I need to pause timer somehow, and start next delay (period) again only after a button has been pressed.
Now if I don't press OK button for let's say 2h, I'll need to press it about 24 (2h/5min delay) times ...
I hope I made myself clear ...

Can anyone give me an advice?
Is java.util.Timer a good solution ?

This is how my code looks like now :




Kuba
 
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kuba and welcome to Javaranch! Can I ask what version of the JDK you are using?
 
Kuba Bernatowicz
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Sorry, I forgot about it.

JDK1.6.0_07
 
Ranch Hand
Posts: 326
Android Mac OS X Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then you should take a look at the java.util.concurrent package and the class ScheduledExecutorService.

There you find what you are looking for. Using timers is "old school".

Also... never EVER do any real work in the main-method. That method is there to initiate the real work and should only contain the code needed to start your application (reading application properties, setting up loggers, setting up data sources and stuff like that).
[ December 05, 2008: Message edited by: Ove Lindstr�m ]
 
Kuba Bernatowicz
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ove,

I googled :
http://gallemore.blogspot.com/2007/05/java-threading-scheduledexecutorservice.html

and last example is just what I needed.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic