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.
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 ]
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.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database