2

Say my web app has two spring cron jobs scheduled to run every minute/hour. Before I'm redeploying my app I can't just shut it down, I must wait for jobs to be finished correctly. I can provide some flag in database or somewhere else, so that jobs will stop to run iteratively - every minute or hour - put some check inside job function to return/do nothing on the next trigger call if such flag checked.

But how can I wait for current job call to finish? And how to see it from ant or other outside script - to choose good time for server shutdown.

There may be solution to put some flag in db or file, and read it. But may be there is some more accurate way - jms or something like that?

beerbajay
  • 19,652
  • 6
  • 58
  • 75
crudo6
  • 345
  • 3
  • 11

2 Answers2

0

If you're using a TaskExecutor to run the "cron" jobs, then you could use the method described by skaffman in this answer to get the results of the task execution. If you need access to this from ant, you could probably use spring's JMS support with ant-jms.

Community
  • 1
  • 1
beerbajay
  • 19,652
  • 6
  • 58
  • 75
0

Instead of using the database you can use JMX. -- But in my humble opinion: If you already use a database but no JMX yet, then use a DB flag, or a simple file, to signal the timer to "stop".

More nice than using the flag and check for every invocation if the flag is set would be shoting shutdown() down the ThreadPoolTaskSchedule or ThreadPoolTaskExecutor. But this would require a second task (run every minute or shorter) to check the flag and then shutdown to scheduler.

To make the ant task wait for a timespan, after setting the flag, to make sure that the last task is done, you can use the WaitFor task.

Ralph
  • 118,862
  • 56
  • 287
  • 383