Top Description Inners Fields Constructors Methods
com.google.common.util.concurrent

pack-priv final Class SequentialExecutor

extends Object
implements Executor
Class Inheritance
All Implemented Interfaces
java.util.concurrent.Executor
Annotations
@J2ktIncompatible
@GwtIncompatible
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkNotNull, com.google.common.util.concurrent.SequentialExecutor.WorkerRunningState.IDLE, .SequentialExecutor.WorkerRunningState.QUEUED, .SequentialExecutor.WorkerRunningState.QUEUING, .SequentialExecutor.WorkerRunningState.RUNNING, java.lang.System.identityHashCode

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 QueueWorker#workOnQueue for details.

RuntimeExceptions 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.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
SequentialExecutor.QueueWorker

Worker that runs tasks from queue until it is empty.

pack-priv static enum

Field Summary

Modifier and TypeField and Description
private final Executor
executor

Underlying executor that all submitted Runnable objects are run on.

private static final LazyLogger
private final Deque<Runnable>
private final SequentialExecutor.QueueWorker
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

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
execute(Runnable
the runnable task
task
)

Implements java.util.concurrent.Executor.execute.

Adds a task to the queue and makes sure a worker thread is running.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

executorback to summary
private final Executor executor

Underlying executor that all submitted Runnable objects are run on.

logback to summary
private static final LazyLogger log
queueback to summary
private final Deque<Runnable> queue
Annotations
@GuardedBy:queue
workerback to summary
private final SequentialExecutor.QueueWorker worker
Annotations
@RetainedWith
workerRunCountback to summary
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. 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.

Annotations
@GuardedBy:queue
workerRunningStateback to summary
private SequentialExecutor.WorkerRunningState workerRunningState

see WorkerRunningState

Annotations
@LazyInit
@GuardedBy:queue

Constructor Detail

SequentialExecutorback to summary
pack-priv SequentialExecutor(Executor executor)

Use MoreExecutors#newSequentialExecutor

Method Detail

executeback to summary
public void execute(Runnable task)

Implements java.util.concurrent.Executor.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.

Parameters
task:Runnable

Doc from java.util.concurrent.Executor.execute.

the runnable task

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
com.google.common.util.concurrent back to summary

private final Class SequentialExecutor.QueueWorker

extends Object
implements Runnable
Class Inheritance
  • java.lang.Object
  • com.google.common.util.concurrent.SequentialExecutor.QueueWorker
All Implemented Interfaces
java.lang.Runnable

Worker that runs tasks from queue until it is empty.

Field Summary

Modifier and TypeField and Description
pack-priv Runnable

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
private void
workOnQueue()

Continues executing tasks from queue until it is empty.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

taskback to summary
pack-priv Runnable task
Annotations
@CheckForNull

Constructor Detail

QueueWorkerback to summary
private QueueWorker()

Method Detail

runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@SuppressWarnings:GuardedBy
@Override
workOnQueueback to summary
private void workOnQueue()

Continues executing tasks from queue until it is empty.

The thread's interrupt bit is cleared before execution of each task.

If the Thread in use is interrupted before or during execution of the tasks in queue, the Executor will complete its tasks, and then restore the interruption. This means that once the Thread returns to the Executor that this Executor composes, the interruption will still be present. If the composed Executor is an ExecutorService, it can respond to shutdown() by returning tasks queued on that Thread after worker drains the queue.

Annotations
@SuppressWarnings:CatchingUnchecked
com.google.common.util.concurrent back to summary

pack-priv final Enum SequentialExecutor.WorkerRunningState

extends Enum<SequentialExecutor.WorkerRunningState>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final SequentialExecutor.WorkerRunningState
IDLE

Runnable is not running and not queued for execution

public static final SequentialExecutor.WorkerRunningState
QUEUED

runnable has been submitted but has not yet begun execution

public static final SequentialExecutor.WorkerRunningState
QUEUING

Runnable is not running, but is being queued for execution

public static final SequentialExecutor.WorkerRunningState

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static SequentialExecutor.WorkerRunningState
public static SequentialExecutor.WorkerRunningState[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

IDLEback to summary
public static final SequentialExecutor.WorkerRunningState IDLE

Runnable is not running and not queued for execution

QUEUEDback to summary
public static final SequentialExecutor.WorkerRunningState QUEUED

runnable has been submitted but has not yet begun execution

QUEUINGback to summary
public static final SequentialExecutor.WorkerRunningState QUEUING

Runnable is not running, but is being queued for execution

RUNNINGback to summary
public static final SequentialExecutor.WorkerRunningState RUNNING

Constructor Detail

WorkerRunningStateback to summary
private WorkerRunningState()

Method Detail

valueOfback to summary
public static SequentialExecutor.WorkerRunningState valueOf(String name)
valuesback to summary
public static SequentialExecutor.WorkerRunningState[] values()