public class StripedExecutorService
extends java.util.concurrent.AbstractExecutorService
In this version, submitted tasks do not necessarily have to implement the StripedObject interface. If they do not, then they will simply be passed onto the wrapped ExecutorService directly.
Idea inspired by Glenn McGregor on the Concurrency-interest mailing list and using the SerialExecutor presented in the Executor interface's JavaDocs.
http://cs.oswego.edu/mailman/listinfo/concurrency-interest
| Constructor and Description |
|---|
StripedExecutorService()
This constructs a StripedExecutorService that wraps a
cached thread pool.
|
StripedExecutorService(int numberOfThreads)
This constructs a StripedExecutorService that wraps a fixed
thread pool with the given number of threads.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
awaitTermination(long timeout,
java.util.concurrent.TimeUnit unit)
Returns true if the wrapped ExecutorService terminates
within the allotted amount of time.
|
void |
execute(java.lang.Runnable command)
Executes the command.
|
boolean |
isShutdown()
Returns true if shutdown() or shutdownNow() have been
called; false otherwise.
|
boolean |
isTerminated()
Returns true if this pool has been terminated, that is, all
the SerialExecutors are empty and the wrapped
ExecutorService has been terminated.
|
protected <T> java.util.concurrent.RunnableFuture<T> |
newTaskFor(java.util.concurrent.Callable<T> callable)
If the callable also implements StripedObject, we store the
stripe object in a thread local, since the actual callable
will be wrapped with a FutureTask.
|
protected <T> java.util.concurrent.RunnableFuture<T> |
newTaskFor(java.lang.Runnable runnable,
T value)
If the runnable also implements StripedObject, we store the
stripe object in a thread local, since the actual runnable
will be wrapped with a FutureTask.
|
void |
shutdown()
Shuts down the StripedExecutorService.
|
java.util.List<java.lang.Runnable> |
shutdownNow()
All the tasks in each of the SerialExecutors are drained
to a list, as well as the tasks inside the wrapped
ExecutorService.
|
<T> java.util.concurrent.Future<T> |
submit(java.util.concurrent.Callable<T> task)
If the task is a StripedObject, we execute it in-order by
its stripe, otherwise we submit it directly to the wrapped
executor.
|
java.util.concurrent.Future<?> |
submit(java.lang.Runnable task)
Delegates the call to submit(task, null).
|
<T> java.util.concurrent.Future<T> |
submit(java.lang.Runnable task,
T result)
If the task is a StripedObject, we execute it in-order by
its stripe, otherwise we submit it directly to the wrapped
executor.
|
java.lang.String |
toString()
Prints information about current state of this executor, the
wrapped executor and the serial executors.
|
public StripedExecutorService()
public StripedExecutorService(int numberOfThreads)
numberOfThreads - the number of threadsprotected <T> java.util.concurrent.RunnableFuture<T> newTaskFor(java.lang.Runnable runnable,
T value)
newTaskFor in class java.util.concurrent.AbstractExecutorServiceprotected <T> java.util.concurrent.RunnableFuture<T> newTaskFor(java.util.concurrent.Callable<T> callable)
newTaskFor in class java.util.concurrent.AbstractExecutorServicepublic java.util.concurrent.Future<?> submit(java.lang.Runnable task)
submit in interface java.util.concurrent.ExecutorServicesubmit in class java.util.concurrent.AbstractExecutorServicepublic <T> java.util.concurrent.Future<T> submit(java.lang.Runnable task,
T result)
submit in interface java.util.concurrent.ExecutorServicesubmit in class java.util.concurrent.AbstractExecutorServicepublic <T> java.util.concurrent.Future<T> submit(java.util.concurrent.Callable<T> task)
submit in interface java.util.concurrent.ExecutorServicesubmit in class java.util.concurrent.AbstractExecutorServicepublic void execute(java.lang.Runnable command)
public void shutdown()
public java.util.List<java.lang.Runnable> shutdownNow()
public boolean isShutdown()
public boolean isTerminated()
public boolean awaitTermination(long timeout,
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException
java.lang.InterruptedExceptionpublic java.lang.String toString()
toString in class java.lang.Object