Interface InterruptableJob
-
- All Superinterfaces:
Job
public interface InterruptableJob extends Job
The interface to be implemented by
that provide a mechanism for having their execution interrupted. It is NOT a requirement for jobs to implement this interface - in fact, for most people, none of their jobs will.Job
sInterrupting a
Job
is very analogous in concept and challenge to normal interruption of aThread
in Java.The means of actually interrupting the Job must be implemented within the
Job
itself (theinterrupt()
method of this interface is simply a means for the scheduler to inform theJob
that a request has been made for it to be interrupted). The mechanism that your jobs use to interrupt themselves might vary between implementations. However the principle idea in any implementation should be to have the body of the job'sexecute(..)
periodically check some flag to see if an interruption has been requested, and if the flag is set, somehow abort the performance of the rest of the job's work. An example of interrupting a job can be found in the java source for the classorg.quartz.examples.DumbInterruptableJob
. It is legal to use some combination ofwait()
andnotify()
synchronization withininterrupt()
andexecute(..)
in order to have theinterrupt()
method block until theexecute(..)
signals that it has noticed the set flag.If the Job performs some form of blocking I/O or similar functions, you may want to consider having the
Job.execute(..)
method store a reference to the callingThread
as a member variable. Then the Implementation of this interfacesinterrupt()
method can callinterrupt()
on that Thread. Before attempting this, make sure that you fully understand whatjava.lang.Thread.interrupt()
does and doesn't do. Also make sure that you clear the Job's member reference to the Thread when the execute(..) method exits (preferably in afinally
block.See Example 7 (org.quartz.examples.example7.DumbInterruptableJob) for a simple implementation demonstration.
- Author:
- James House
- See Also:
Job
,StatefulJob
,Scheduler.interrupt(JobKey)
,Scheduler.interrupt(String)
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
interrupt()
Called by the
when a user interrupts theScheduler
Job
.
-
-
-
Method Detail
-
interrupt
void interrupt() throws UnableToInterruptJobException
Called by the
when a user interrupts theScheduler
Job
.- Throws:
UnableToInterruptJobException
- if there is an exception while interrupting the job.
-
-