1

How can I schedule time to stop and kill a single job from the begining of execution task ? For example determine that if after an hour the task is still working, it will stop and remove. (I don't mean to Repeated task) I use with org.quartz.Scheduler and org.quartz.JobDetail in java

many thanks

cls
  • 109
  • 1
  • 3
  • 7

3 Answers3

0

You might want to look into the org.quartz.InterruptableJob interface (which extends Job) and the interrupt() method on the scheduler.

If you want to actually call Thread.interrupt() on the threads in the worker thread pool you'd likely need your implementation of org.quartz.spi.ThreadPool.

Sathwick
  • 1,311
  • 1
  • 8
  • 10
  • How can determinate the life time of task before starting the job and don't call to method at the moment of arrive stop time? – cls Aug 08 '11 at 10:06
  • You can always add one more job to kill other jobs and schedule it accordingly. – Sathwick Aug 09 '11 at 03:17
0

I think it would probably be easier for you if you coded this functionality within the job itself. I say this for a few reasons:

  1. Its very easy to track how long the job has been running from within the job
  2. If the job needs to stop, its easy to stop gracefully and set aside the work it was doing
  3. Your job may be able to tell progress on the works its doing, and if its close to being done let it go beyond the kill-time + 10% or something
Jason Clawson
  • 1,027
  • 7
  • 9
0
If you change your class to implement StatefulJob instead of Job, Quartz will take care of this for you. From the StatefulJob javadoc:

stateful jobs are not allowed to execute concurrently, which means new triggers that occur before the completion of the execute(xx) method will be delayed.

StatefulJob extends Job and does not add any new methods, so all you need to do to get the behaviour you want is change this:

public class YourJob implements org.quartz.Job {
    void execute(JobExecutionContext context) {/*implementation omitted*/}
}
To this:

public class YourJob implements org.quartz.StatefulJob {
    void execute(JobExecutionContext context) {/*implementation omitted*/}
} 

Couple more options are here

Community
  • 1
  • 1
Sankalp
  • 2,030
  • 7
  • 30
  • 41