• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Calling a thread daily in the server automatically  RSS feed

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have to run a thread automatically daily which extends the present date by 30 days to all users. I am getting this and it is working fine and deployed the same on the server and I am getting the results correct but the major problem is whenever i restart my server the thread is called everytime i restart the server by which the date is extended to 30 more days again and this is happening everytime I restart my server.

Thanks in advance
regards
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May be you can try schedular software for this.

You can use OpenSymphony Quartz scheduler. Its open source.

www.opensymphony.com/quartz/
 
Rancher
Posts: 42974
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quartz sounds like overkill for this. Instead of scheduling the thread to execute right when you start the server, and then every 24 hours, have it execute at a fixed time, say, 3am every morning. Then it doesn't matter when and how often you restart the server. The java.util.Timer and TimerTask classes can help with this.

As a side note, have you considered controlling this job using cron, instead of executing it in the app server?
[ January 05, 2006: Message edited by: Ulf Dittmer ]
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree that for a single event like this you can throw your own timer. Setting it is mildly tricky. If I start the server at 4:00 AM it won't know whether the 3:00 AM timer fired or maybe the server has been down since midnight. You may have to persist the "last time fired" or the "next scheduled fire" to a database or something.

CRON is certainly an option, too, if you can run the task outside the main JVM. I think CRON and Quartz have already solved the persistence problem and have policies for how to "make up" if a scheduled event is missed due to something being down.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!