public abstract class ProtectedTimerTask
extends java.lang.Object
implements java.util.concurrent.Delayed, java.lang.Runnable
ProtectedTimer.
Implementations of this class should be designed to catch and handle
OutOfMemoryError to the degree possible.
| Modifier and Type | Class and Description |
|---|---|
private static class |
ProtectedTimerTask.TaskStatus
Possible task states.
|
| Modifier and Type | Field and Description |
|---|---|
private long |
nextExecutionTime
Absolute time (in milliseconds) of the next execution of the task.
|
private long |
periodicalDelay
Interval between the subsequent executions of the task.
|
private ProtectedTimerTask.TaskStatus |
taskStatus
Current task status.
|
| Constructor and Description |
|---|
ProtectedTimerTask() |
| Modifier and Type | Method and Description |
|---|---|
void |
cancel()
Cancels the task.
|
int |
compareTo(java.util.concurrent.Delayed delayed)
Compares the delay of this timer task with the delay of the specified
task.
|
long |
getDelay(java.util.concurrent.TimeUnit timeUnit)
Returns the remaining delay associated with this timer task, in the
given time unit.
|
(package private) void |
initialSchedule(long initialDelay,
long periodicalDelay)
Prepares the task for its initial execution.
|
boolean |
isCancelled()
Determines whether this task is cancelled.
|
(package private) boolean |
reschedule()
Prepares the task for the next execution.
|
abstract void |
run()
Main task code.
|
private ProtectedTimerTask.TaskStatus taskStatus
private long periodicalDelay
private long nextExecutionTime
public abstract void run()
run in interface java.lang.Runnablepublic long getDelay(java.util.concurrent.TimeUnit timeUnit)
getDelay in interface java.util.concurrent.DelayedtimeUnit - the time unitpublic int compareTo(java.util.concurrent.Delayed delayed)
compareTo in interface java.lang.Comparable<java.util.concurrent.Delayed>delayed - the timer task which delay should be compared to the delay of
this task.public void cancel()
public boolean isCancelled()
void initialSchedule(long initialDelay,
long periodicalDelay)
initialDelay - Delay before execution of the task.periodicalDelay - Interval between the subsequent executions of the task.boolean reschedule()
true if the task was successfully rescheduled.
false if task is completed and shouldn't be
rescheduled.