ThreadPool
public interface Scheduler
Modifier and Type | Interface | Description |
---|---|---|
static interface |
Scheduler.Cancellable |
This interface represents an object whose execution may be cancelled during runtime.
|
static class |
Scheduler.ReschedulingRunnable |
This class encapsulates the scheduling of a
Runnable that needs to be repeated on a interval. |
Modifier and Type | Method | Description |
---|---|---|
static boolean |
awaitTermination(java.util.concurrent.ScheduledThreadPoolExecutor scheduledThreadPoolExecutor,
long timeout,
java.util.concurrent.TimeUnit timeUnit) |
|
static java.util.concurrent.ScheduledThreadPoolExecutor |
initScheduler(Settings settings) |
|
default java.lang.Runnable |
preserveContext(java.lang.Runnable command) |
Does nothing by default but can be used by subclasses to save the current thread context and wraps the command in a Runnable
that restores that context before running the command.
|
java.util.concurrent.ScheduledFuture<?> |
schedule(TimeValue delay,
java.lang.String executor,
java.lang.Runnable command) |
Schedules a one-shot command to be run after a given delay.
|
default Scheduler.Cancellable |
scheduleWithFixedDelay(java.lang.Runnable command,
TimeValue interval,
java.lang.String executor) |
Schedules a periodic action that runs on scheduler thread.
|
static boolean |
terminate(java.util.concurrent.ScheduledThreadPoolExecutor scheduledThreadPoolExecutor,
long timeout,
java.util.concurrent.TimeUnit timeUnit) |
static java.util.concurrent.ScheduledThreadPoolExecutor initScheduler(Settings settings)
static boolean terminate(java.util.concurrent.ScheduledThreadPoolExecutor scheduledThreadPoolExecutor, long timeout, java.util.concurrent.TimeUnit timeUnit)
static boolean awaitTermination(java.util.concurrent.ScheduledThreadPoolExecutor scheduledThreadPoolExecutor, long timeout, java.util.concurrent.TimeUnit timeUnit)
default java.lang.Runnable preserveContext(java.lang.Runnable command)
java.util.concurrent.ScheduledFuture<?> schedule(TimeValue delay, java.lang.String executor, java.lang.Runnable command)
preserveContext(Runnable)
on the runnable before passing
it to this method.
The command runs on scheduler thread. Do not run blocking calls on the scheduler thread. Subclasses may allow
to execute on a different executor, in which case blocking calls are allowed.delay
- delay before the task executesexecutor
- the name of the executor that has to execute this task. Ignored in the default implementation but can be used
by subclasses that support multiple executors.command
- the command to runEsRejectedExecutionException
- if the task cannot be scheduled for executiondefault Scheduler.Cancellable scheduleWithFixedDelay(java.lang.Runnable command, TimeValue interval, java.lang.String executor)
command
- the action to takeinterval
- the delay intervalexecutor
- the name of the executor that has to execute this task. Ignored in the default implementation but can be used
by subclasses that support multiple executors.Scheduler.Cancellable
that can be used to cancel the subsequent runs of the command. If the command is running, it will
not be interrupted.