Schedules a task to run periodically after a delay. The
TaskManager
will wait for the specified number of milliseconds, and then call the task's {@link Task#run run} method assoon as possible after the completion of the task in which this method is called, according to its scheduling algorithm. It will also arrange to run the task periodically at the specified interval following the delay until the {@link PeriodicTaskHandle#cancel PeriodicTaskHandle.cancel} method is called on the associated handle.At the start of each period, which occurs
period
milliseconds after the scheduled start of the previous period, a new task will be scheduled to run. The
TaskManager
will make a best effort to run a new task in each period, but even if the task cannot be run in one period, a new task will always be scheduled for the following period. The
TaskManager
will wait until the current attempt to run the task has ended before making another attempt to run it, regardless of whether the attempts are for the same or different periods.
If the call to the run
method throws an exception, that exception implements {@link ExceptionRetryStatus}, and its {@link ExceptionRetryStatus#shouldRetry shouldRetry} method returnstrue
, then the TaskManager
will make further attempts to run the task. It will continue those attempts until either an attempt succeeds or it notices an exception is thrown that is not retryable. Note that calls to PeriodicTaskHandle.cancel
have no effect on attempts to retry a task after the first attempt. The TaskManager
is permitted to treat a non-retryable exception as a hint. In particular, a task that throws a non-retryable exception may be retried if the node running the task crashes.
@param task the task to run
@param delay the number of milliseconds to delay before running thetask
@param period the number of milliseconds that should elapse betweenthe starts of periodic attempts to run the task
@return a handle for managing the scheduling of the task
@throws IllegalArgumentException if task
does notimplement {@link Serializable}, if delay is less than 0
, or if period is less than 0
@throws TaskRejectedException if the TaskManager
refusesto accept the task because of resource limitations
@throws TransactionException if the operation failed because of aproblem with the current transaction