Class SequentialExecutor
java.lang.Object
com.google.common.util.concurrent.SequentialExecutor
- All Implemented Interfaces:
Executor
Executor ensuring that all Runnables submitted are executed in order, using the provided
Executor, and sequentially such that no two will ever be running at the same time.
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)
.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final class
Worker that runs tasks fromqueue
until it is empty.(package private) static enum
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Executor
Underlying executor that all submitted Runnable objects are run on.private static final LazyLogger
private final SequentialExecutor.QueueWorker
private long
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. -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
log
-
executor
Underlying executor that all submitted Runnable objects are run on. -
queue
-
workerRunningState
-
workerRunCount
private long workerRunCountThis 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. Without this counter, it would observe the QUEUING state and set it to QUEUED, and the worker would never be scheduled again for future submissions. -
worker
-
-
Constructor Details
-
SequentialExecutor
SequentialExecutor(Executor executor)
-
-
Method Details
-
execute
Adds a task to the queue and makes sure a worker thread is running.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. -
toString
-