final class SequentialExecutor
extends java.lang.Object
implements java.util.concurrent.Executor
Tasks submitted to execute(Runnable)
are executed in FIFO order.
The execution of tasks is done by one thread as long as there are tasks left in the queue.
When a task is interrupted, execution of subsequent tasks
continues. See SequentialExecutor.QueueWorker.workOnQueue()
for details.
RuntimeException
s thrown by tasks are simply logged and the executor keeps trucking.
If an Error
is thrown, the error will propagate and execution will stop until it is
restarted by a call to execute(java.lang.Runnable)
.
Modifier and Type | Class and Description |
---|---|
private class |
SequentialExecutor.QueueWorker
Worker that runs tasks from
queue until it is empty. |
(package private) static class |
SequentialExecutor.WorkerRunningState |
Modifier and Type | Field and Description |
---|---|
private java.util.concurrent.Executor |
executor
Underlying executor that all submitted Runnable objects are run on.
|
private static java.util.logging.Logger |
log |
private java.util.Deque<java.lang.Runnable> |
queue |
private SequentialExecutor.QueueWorker |
worker |
private long |
workerRunCount
This counter prevents an ABA issue where a thread may successfully schedule the worker, the
worker runs and exhausts the queue, another thread enqueues a task and fails to schedule the
worker, and then the first thread's call to delegate.execute() returns.
|
private SequentialExecutor.WorkerRunningState |
workerRunningState
|
Constructor and Description |
---|
SequentialExecutor(java.util.concurrent.Executor executor)
|
Modifier and Type | Method and Description |
---|---|
void |
execute(java.lang.Runnable task)
Adds a task to the queue and makes sure a worker thread is running.
|
java.lang.String |
toString() |
private static final java.util.logging.Logger log
private final java.util.concurrent.Executor executor
private final java.util.Deque<java.lang.Runnable> queue
private SequentialExecutor.WorkerRunningState workerRunningState
private long workerRunCount
private final SequentialExecutor.QueueWorker worker
public void execute(java.lang.Runnable task)
If this method throws, e.g. a RejectedExecutionException
from the delegate executor,
execution of tasks will stop until a call to this method is made.
execute
in interface java.util.concurrent.Executor
public java.lang.String toString()
toString
in class java.lang.Object