public abstract class ReschedulingOperation extends java.lang.Object
SubmitterScheduler.scheduleWithFixedDelay(Runnable, long, long), this can provide the ability to only have the task scheduled if there is work to do. In addition it provides the ability to change the frequency of execution without needing to remove and re-add the task.
This task will only schedule or reschedule itself if it has been notified there is work to do.
It is assumed that after execution all work is complete. If there is additional work to
perform, then the task should invoke
signalToRun() before it completes to ensure that
it is rescheduled at the current set delay. Because of that behavior there is no way to remove
this task from the scheduler, instead you must just ensure that
signalToRun() is not
invoked to prevent the task from rescheduling itself.
An additional advantage to using this over scheduling a recurring task is that you don't have
to worry about removing the task before garbage collection occurs (ie no cleanup, just stop
|Modifier and Type||Method and Description|
Check to see if this operation is either currently running, or scheduled to run.
Adjusts the delay at which this task is scheduled or rescheduled.
Invoke to indicate that this operation has stuff to do.
public boolean isActive()
truemeans this operation still has things to do
public void setScheduleDelay(long scheduleDelay)
run()to change how long till it executes next.
scheduleDelay- Delay in milliseconds to schedule operation out on, can not be negative
public void signalToRunImmediately(boolean runOnCallingThreadIfPossible)
signalToRun()except that any configured schedule / delay will be ignored and instead the task will try to run ASAP.
trueto run the task on the invoking thread if possible
public void signalToRun()
If you want to signal the task to run immediately (ignore the schedule delay) please see