This class can be used as a synchronization aid that assists a number of parties in running a task in a mutually exclusive fashion.
To run the task, a party invokes runOrSchedule. To permanently
prevent the task from subsequent runs, the party invokes stop.
The parties can, but do not have to, operate in different threads.
The task can be either synchronous ( completes when its run
method returns ), or asynchronous ( completed when its
DeferredCompleter is explicitly completed ).
The next run of the task will not begin until the previous run has finished.
The task may invoke runOrSchedule itself, which may be a normal
situation.
| Modifier and Type | Class and Description |
|---|---|
| public abstract static class | SequentialScheduler.
A simple and self-contained task that completes once its |
| public abstract static class | SequentialScheduler.
An interface to signal the completion of a |
| public static class | SequentialScheduler.
A task that runs its main loop within a block protected by a lock to provide memory visibility between runs. |
| public static interface | SequentialScheduler.
A restartable task. |
| private class | SequentialScheduler.
An auxiliary task that starts the restartable task:
|
| private class | SequentialScheduler.
The only concrete |
| Modifier and Type | Field and Description |
|---|---|
| private static final int | |
| private static final int | |
| private final SequentialScheduler. | |
| private static final int | |
| private static final int | |
| private final SequentialScheduler. | |
| private final SequentialScheduler. | |
| private final AtomicInteger | |
| private static final int |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | |
| public static SequentialScheduler | Returns: a newSequentialScheduler that executes the provided
mainLoop from within a LockingRestartableTask.The main loop of the new sequential scheduler mainLoop)Returns a new |
| public void | |
| public void | runOrSchedule(Executor
An executor in which to execute the task, if the task needs
to be executed. executor)Executes or schedules the task to be executed in the provided executor. |
| private void | |
| public void |
| AGAIN | back to summary |
|---|---|
| private static final int AGAIN | |
| BEGIN | back to summary |
|---|---|
| private static final int BEGIN | |
| completer | back to summary |
|---|---|
| private final SequentialScheduler. | |
| END | back to summary |
|---|---|
| private static final int END | |
| OFFLOAD | back to summary |
|---|---|
| private static final int OFFLOAD | |
| restartableTask | back to summary |
|---|---|
| private final SequentialScheduler. | |
| schedulableTask | back to summary |
|---|---|
| private final SequentialScheduler. | |
| state | back to summary |
|---|---|
| private final AtomicInteger state | |
| STOP | back to summary |
|---|---|
| private static final int STOP | |
| SequentialScheduler | back to summary |
|---|---|
| public SequentialScheduler(SequentialScheduler. | |
| isStopped | back to summary |
|---|---|
| public boolean isStopped() Tells whether, or not, this scheduler has been permanently stopped. Should be used from inside the task to poll the status of the scheduler, pretty much the same way as it is done for threads:
| |
| lockingScheduler | back to summary |
|---|---|
| public static SequentialScheduler lockingScheduler(Runnable mainLoop) Returns a new API Note This is equivalent to calling
| |
| runOrSchedule | back to summary |
|---|---|
| public void runOrSchedule() Runs or schedules the task to be run. Implementation Specification The recursion which is possible here must be bounded:
Implementation Note The recursion in this implementation has the maximum depth of 1. | |
| runOrSchedule | back to summary |
|---|---|
| public void runOrSchedule(Executor executor) Executes or schedules the task to be executed in the provided executor. This method can be used when potential executing from a calling thread is not desirable. API Note The given executor can be
| |
| runOrSchedule | back to summary |
|---|---|
| private void runOrSchedule(SequentialScheduler. | |
| stop | back to summary |
|---|---|
| public void stop() Stops this scheduler. Subsequent invocations of If the task has already begun, this invocation will not affect it,
unless the task itself uses | |
run
method returns.
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public final void | run(SequentialScheduler.
Implements jdk. The body of the task. |
| protected abstract void |
| CompleteRestartableTask | back to summary |
|---|---|
| public CompleteRestartableTask() | |
| run | back to summary |
|---|---|
| public final void run(SequentialScheduler. Implements jdk. Doc from jdk. The body of the task.
| |
| run | back to summary |
|---|---|
| protected abstract void run() The body of the task. | |
RestartableTask.
The invocation of complete completes the task. The invocation
of complete may restart the task, if an attempt has previously
been made to run the task while it was already running.
API Note
DeferredCompleter is useful when a task is not necessary
complete when its run method returns, but will complete at a
later time, and maybe in different thread. This type exists for
readability purposes at use-sites only.
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public abstract void |
| DeferredCompleter | back to summary |
|---|---|
| private DeferredCompleter() Extensible from this (outer) class ONLY. | |
| complete | back to summary |
|---|---|
| public abstract void complete() Completes the task. Must be called once, and once only. | |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected void | run()
Implements abstract jdk. The body of the task. |
| lock | back to summary |
|---|---|
| private final Lock lock | |
| mainLoop | back to summary |
|---|---|
| private final Runnable mainLoop | |
| LockingRestartableTask | back to summary |
|---|---|
| public LockingRestartableTask(Runnable mainLoop) | |
| run | back to summary |
|---|---|
| protected void run() Implements abstract jdk. Doc from jdk. The body of the task.
| |
| Modifier and Type | Method and Description |
|---|---|
| public void | run(SequentialScheduler.
A completer that must be invoked once, and only once,
when this task is logically finished taskCompleterThe body of the task. |
| run | back to summary |
|---|---|
| public void run(SequentialScheduler. The body of the task.
| |
restartableTask.run(completer).
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public void |
| SchedulableTask | back to summary |
|---|---|
| private SchedulableTask() | |
| run | back to summary |
|---|---|
| public void run() Implements java. Doc from java. Runs this operation.
| |
DeferredCompleter implementation.
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public void | complete()
Implements abstract jdk. Completes the task. |
| TryEndDeferredCompleter | back to summary |
|---|---|
| private TryEndDeferredCompleter() | |
| complete | back to summary |
|---|---|
| public void complete() Implements abstract jdk. Doc from jdk. Completes the task. Must be called once, and once only.
| |