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
invoking signalToRun()
).
Modifier and Type | Method and Description |
---|---|
boolean |
isActive()
Check to see if this operation is either currently running, or scheduled to run.
|
void |
setScheduleDelay(long scheduleDelay)
Adjusts the delay at which this task is scheduled or rescheduled.
|
void |
signalToRun()
Invoke to indicate that this operation has stuff to do.
|
void |
signalToRunImmediately(boolean runOnCallingThreadIfPossible)
Similar to
signalToRun() except that any configured schedule / delay will be ignored
and instead the task will try to run ASAP. |
public boolean isActive()
true
means this operation still has things to dopublic 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 negativepublic void signalToRunImmediately(boolean runOnCallingThreadIfPossible)
signalToRun()
except that any configured schedule / delay will be ignored
and instead the task will try to run ASAP.runOnCallingThreadIfPossible
- true
to run the task on the invoking thread if possiblepublic void signalToRun()
If you want to signal the task to run immediately (ignore the schedule delay) please see
signalToRunImmediately(boolean)
.