public final class OrderedExecutor extends java.util.concurrent.AbstractExecutorService implements BlockingExecutorService
execute(Runnable) method that
happens-after another call A to the same method, will result in B's task running after A's.| Modifier and Type | Class and Description |
|---|---|
private class |
OrderedExecutor.Runner |
| Modifier and Type | Field and Description |
|---|---|
private boolean |
blocking |
private java.util.concurrent.Executor |
handoffExecutor |
private java.util.concurrent.locks.Lock |
lock |
private java.util.concurrent.Executor |
parent |
private java.util.Queue<java.lang.Runnable> |
queue |
private java.util.concurrent.locks.Condition |
removeCondition |
private java.lang.Runnable |
runner |
private boolean |
running |
| Constructor and Description |
|---|
OrderedExecutor(java.util.concurrent.Executor parent)
Construct a new instance using an unbounded FIFO queue.
|
OrderedExecutor(java.util.concurrent.Executor parent,
int queueLength)
Construct a new instance using a bounded FIFO queue of the given size and a blocking reject policy.
|
OrderedExecutor(java.util.concurrent.Executor parent,
int queueLength,
boolean blocking,
java.util.concurrent.Executor handoffExecutor)
Construct a new instance using a bounded FIFO queue of the given size and a handoff reject policy.
|
OrderedExecutor(java.util.concurrent.Executor parent,
int queueLength,
java.util.concurrent.Executor handoffExecutor)
Construct a new instance using a bounded FIFO queue of the given size and a handoff reject policy.
|
OrderedExecutor(java.util.concurrent.Executor parent,
java.util.Queue<java.lang.Runnable> queue)
Construct a new instance using the given queue and a blocking reject policy.
|
OrderedExecutor(java.util.concurrent.Executor parent,
java.util.Queue<java.lang.Runnable> queue,
boolean blocking,
java.util.concurrent.Executor handoffExecutor)
Construct a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
awaitTermination(long timeout,
java.util.concurrent.TimeUnit unit) |
void |
execute(java.lang.Runnable task)
Run a task.
|
void |
executeBlocking(java.lang.Runnable task)
Execute a task, blocking until it can be accepted, or until the calling thread is interrupted.
|
void |
executeBlocking(java.lang.Runnable task,
long timeout,
java.util.concurrent.TimeUnit unit)
Execute a task, blocking until it can be accepted, a timeout elapses, or the calling thread is interrupted.
|
void |
executeNonBlocking(java.lang.Runnable task)
Execute a task, without blocking.
|
boolean |
isShutdown() |
boolean |
isTerminated() |
void |
shutdown() |
java.util.List<java.lang.Runnable> |
shutdownNow() |
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor, submit, submit, submitprivate final java.util.concurrent.Executor parent
private final java.lang.Runnable runner
private final java.util.concurrent.locks.Lock lock
private final java.util.concurrent.locks.Condition removeCondition
private final java.util.Queue<java.lang.Runnable> queue
private boolean running
private boolean blocking
private java.util.concurrent.Executor handoffExecutor
public OrderedExecutor(java.util.concurrent.Executor parent)
parent - the parent to delegate tasks topublic OrderedExecutor(java.util.concurrent.Executor parent,
java.util.Queue<java.lang.Runnable> queue)
parent - the parent to delegate tasks toqueue - the queue to use to hold taskspublic OrderedExecutor(java.util.concurrent.Executor parent,
int queueLength)
parent - the parent to delegate tasks toqueueLength - the fixed length of the queue to use to hold taskspublic OrderedExecutor(java.util.concurrent.Executor parent,
int queueLength,
java.util.concurrent.Executor handoffExecutor)
parent - the parent executorqueueLength - the fixed length of the queue to use to hold taskshandoffExecutor - the executor to hand tasks to if the queue is fullpublic OrderedExecutor(java.util.concurrent.Executor parent,
java.util.Queue<java.lang.Runnable> queue,
boolean blocking,
java.util.concurrent.Executor handoffExecutor)
parent - the parent executorqueue - the task queue to useblocking - true if rejected tasks should block, false if rejected tasks should be handed offhandoffExecutor - the executor to hand tasks to if the queue is fullpublic OrderedExecutor(java.util.concurrent.Executor parent,
int queueLength,
boolean blocking,
java.util.concurrent.Executor handoffExecutor)
parent - the parent executorqueueLength - the fixed length of the queue to use to hold tasksblocking - true if rejected tasks should block, false if rejected tasks should be handed offhandoffExecutor - the executor to hand tasks to if the queue is fullpublic void execute(java.lang.Runnable task)
execute in interface java.util.concurrent.Executorexecute in interface BlockingExecutortask - the task to run.public void executeBlocking(java.lang.Runnable task)
throws java.util.concurrent.RejectedExecutionException,
java.lang.InterruptedException
BlockingExecutorexecuteBlocking in interface BlockingExecutortask - the task to submitStoppedExecutorException - if the executor was shut down before the task was acceptedThreadCreationException - if a thread could not be created for some reasonjava.util.concurrent.RejectedExecutionException - if execution is rejected for some other reasonjava.lang.InterruptedException - if the current thread was interrupted before the task could be acceptedpublic void executeBlocking(java.lang.Runnable task,
long timeout,
java.util.concurrent.TimeUnit unit)
throws java.util.concurrent.RejectedExecutionException,
java.lang.InterruptedException
BlockingExecutorexecuteBlocking in interface BlockingExecutortask - the task to submittimeout - the amount of time to waitunit - the unit of timeExecutionTimedOutException - if the timeout elapsed before a task could be acceptedStoppedExecutorException - if the executor was shut down before the task was acceptedThreadCreationException - if a thread could not be created for some reasonjava.util.concurrent.RejectedExecutionException - if execution is rejected for some other reasonjava.lang.InterruptedException - if the current thread was interrupted before the task could be acceptedpublic void executeNonBlocking(java.lang.Runnable task)
throws java.util.concurrent.RejectedExecutionException
BlockingExecutorexecuteNonBlocking in interface BlockingExecutortask - the task to submitStoppedExecutorException - if the executor was shut down before the task was acceptedThreadCreationException - if a thread could not be created for some reasonjava.util.concurrent.RejectedExecutionException - if execution is rejected for some other reasonpublic boolean isShutdown()
isShutdown in interface java.util.concurrent.ExecutorServicepublic boolean isTerminated()
isTerminated in interface java.util.concurrent.ExecutorServicepublic boolean awaitTermination(long timeout,
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException
awaitTermination in interface java.util.concurrent.ExecutorServicejava.lang.InterruptedExceptionpublic void shutdown()
shutdown in interface java.util.concurrent.ExecutorServicepublic java.util.List<java.lang.Runnable> shutdownNow()
shutdownNow in interface java.util.concurrent.ExecutorService