O - The type of object for which work is registered.public class ObjectOneWorkExecutor<O> extends AbstractObjectSpecificExecutor<O,O,Pair<java.lang.Runnable,java.lang.Runnable>>
As object-specific executor, the indexed objects are the same as the registered objects. The
runtime data consists of a pair of runnables that are registered for the corresponding object.
The first runnable is the one pending to be executed after the
current work but before a flush. This work will be cancelled if flushing is with abortion. It
will be null if there is no more work or if the work should block until the next
flush. The second runnable is work which is added while a flush is pending. This is executed
right after all pending flushs have been executed.
To prevent starvation, each piece of work will be executed by an arbitrary thread; work for the
same object will only be executed by the same thread when shutting down.
java.util.concurrent.ThreadPoolExecutor.AbortPolicy, java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy, java.util.concurrent.ThreadPoolExecutor.DiscardOldestPolicy, java.util.concurrent.ThreadPoolExecutor.DiscardPolicy| Modifier and Type | Field and Description |
|---|---|
protected boolean |
blockUntilFlush
Whether work should be blocked for each object until the next flush.
|
protected java.util.Collection<java.lang.Thread> |
overridingWork
The threads that are currently submitting or executing a piece of work that should override
existing (pending) work.
|
abortCount, flushPending, logger, objects, shutdownPendingfullSize, realCoreSize, realMaxSize, workSizeactiveThreads, completedTasks, submittedTasks| Constructor and Description |
|---|
ObjectOneWorkExecutor(boolean blockUntilFlush,
Adept2ThreadFactory threadFactory)
Creates a new thread pool executor with an unlimited amount of threads and objects, accepting
exactly one piece of work per object.
|
ObjectOneWorkExecutor(boolean blockUntilFlush,
int corePoolSize,
int maxPoolSize,
boolean prestart,
Adept2ThreadFactory threadFactory)
Creates a new thread pool executor with the designated (maximum) amount of (core) threads (and
unlimited objects), accepting exactly one piece of work per object.
|
| Modifier and Type | Method and Description |
|---|---|
protected ObjectRunnable<O,O> |
addRunnable(O registeredObject,
O indexObject,
java.lang.Runnable task)
Adds the designated runnable for the designated object and index object to this executor.
|
protected <T> Pair<java.util.concurrent.Future<T>,java.util.Map<O,Pair<java.lang.Runnable,java.lang.Runnable>>> |
cancelAndFlush(boolean shutdownRequest,
java.util.Map<O,Pair<java.lang.Runnable,java.lang.Runnable>> pending,
java.util.concurrent.Callable<T> task,
java.util.Collection<ObjectRunnable<O,O>> objectRunnables)
Cancels the designated pending work (if appropriate), flushes (i. e. waits for or aborts the
designated runnables) and executes the designated task.
|
protected void |
clearAbortedPendingWork(boolean shutdownRequest)
Removes all pending work that should be aborted for an aborting flush, that is, it removes the
from the data structures, e. g.
|
void |
executeOverride(O object,
java.lang.Runnable task)
Executes the designated task for the designated object and overrides pending work if this
exists.
|
protected void |
executeShutdown(java.lang.Runnable shutdown)
Executes the designated shutdown task which contains a flush calling
ThreadPoolExecutor.shutdown() without abortion. |
protected O |
getIndexObjectFor(O object)
Gets the object used for managing and executing runnables within this executor.
|
protected java.util.List<java.lang.Runnable> |
getOutstandingRunnables(java.util.Map<O,Pair<java.lang.Runnable,java.lang.Runnable>> outstandingWork)
Gets a list of runnables which have not been executed based on the designated outstanding work.
|
protected void |
restartPendingWork()
Checks for whether there is work pending for after a restart.
|
<T> java.util.concurrent.Future<T> |
submitOverride(O object,
java.util.concurrent.Callable<T> task)
Submits the designated task for the designated object and overrides existing pending work.
|
java.util.concurrent.Future<?> |
submitOverride(O object,
java.lang.Runnable task)
Submits the designated task for the designated object and overrides existing pending work.
|
execute, flushAndExecute, flushAndExecuteUnchecked, isShutdown, restart, shutdown, shutdownNow, shutdownRunnableRun, submit, submit, submitAndFlushafterExecute, executebeforeExecute, newTaskFor, newTaskFor, setLogExecuteCallStack, updateQueueLimitallowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, finalize, getActiveCount, getCompletedTaskCount, getCorePoolSize, getKeepAliveTime, getLargestPoolSize, getMaximumPoolSize, getPoolSize, getQueue, getRejectedExecutionHandler, getTaskCount, getThreadFactory, isTerminated, isTerminating, prestartAllCoreThreads, prestartCoreThread, purge, remove, setCorePoolSize, setKeepAliveTime, setMaximumPoolSize, setRejectedExecutionHandler, setThreadFactory, terminated, toStringprotected final boolean blockUntilFlush
protected final java.util.Collection<java.lang.Thread> overridingWork
addRunnable(Object, Object, Runnable), using this collection avoids the need for an
additional method parameter (which would require an ugly interface change).public ObjectOneWorkExecutor(boolean blockUntilFlush,
Adept2ThreadFactory threadFactory)
blockUntilFlush - Whether work should be blocked for each object until the next flush.
Otherwise work is allowed as soon as the work of the object has started.threadFactory - The factory to use when the executor creates a new thread.public ObjectOneWorkExecutor(boolean blockUntilFlush,
int corePoolSize,
int maxPoolSize,
boolean prestart,
Adept2ThreadFactory threadFactory)
blockUntilFlush - Whether work should be blocked for each object until the next flush.
Otherwise work is allowed as soon as the work of the object has started.corePoolSize - The number of threads to keep in the pool, even if they are idle.maxPoolSize - The maximum number of threads to allow in the pool.prestart - Whether all core threads should be prestarted.threadFactory - The factory to use when the executor creates a new thread.public void executeOverride(O object, java.lang.Runnable task)
object - The object for which to execute the designated task.task - The task which to execute.java.util.concurrent.RejectedExecutionException - if the executor has been shut
down, a RejectedExecutionException will be thrown.AbstractObjectSpecificExecutor.execute(Object, Runnable)public java.util.concurrent.Future<?> submitOverride(O object, java.lang.Runnable task)
object - The object for which to execute the designated task.task - The task which to execute.Future representing pending completion of the taskjava.util.concurrent.RejectedExecutionException - if the executor has been shut
down, a RejectedExecutionException will be thrown.AbstractObjectSpecificExecutor.submit(Object, Runnable)public <T> java.util.concurrent.Future<T> submitOverride(O object, java.util.concurrent.Callable<T> task)
object - The object for which to execute the designated task.task - The task which to execute.Future representing pending completion of the taskjava.util.concurrent.RejectedExecutionException - if the executor has been shut
down, a RejectedExecutionException will be thrown.AbstractObjectSpecificExecutor.submit(Object, Callable)protected O getIndexObjectFor(O object)
AbstractObjectSpecificExecutorgetIndexObjectFor in class AbstractObjectSpecificExecutor<O,O,Pair<java.lang.Runnable,java.lang.Runnable>>object - The object for which a runnable is registered.protected ObjectRunnable<O,O> addRunnable(O registeredObject, O indexObject, java.lang.Runnable task)
AbstractObjectSpecificExecutorCachedThreadPoolExecutor.execute(Runnable). If they return null, they
have to assign the runnable to an active element eventually and arbitrarily.
The caller has the lock on objects.
addRunnable in class AbstractObjectSpecificExecutor<O,O,Pair<java.lang.Runnable,java.lang.Runnable>>registeredObject - The object for which this runnable has been registered.indexObject - The object with which this runnable is managed and executed within the
corresponding object-specific executor service.task - The task which to execute.CachedThreadPoolExecutor.execute(Runnable), which means the runnable
will be executed independently from other work and a new thread may be started for it.protected void clearAbortedPendingWork(boolean shutdownRequest)
objects. This method only affects data structures,
it does not affect any executed work. The caller will take care of this shortly.
The caller has the lock on objects.
Only removes the entries which do not have work pending for after a flush in case this is no
shutdown request. Otherwise all objects and all work will be removed.
clearAbortedPendingWork in class AbstractObjectSpecificExecutor<O,O,Pair<java.lang.Runnable,java.lang.Runnable>>shutdownRequest - Whether this flush is caused by a AbstractObjectSpecificExecutor.shutdownNow(). In this case
all work has to be aborted, even the work pending after a flush.protected <T> Pair<java.util.concurrent.Future<T>,java.util.Map<O,Pair<java.lang.Runnable,java.lang.Runnable>>> cancelAndFlush(boolean shutdownRequest, java.util.Map<O,Pair<java.lang.Runnable,java.lang.Runnable>> pending, java.util.concurrent.Callable<T> task, java.util.Collection<ObjectRunnable<O,O>> objectRunnables)
AbstractObjectSpecificExecutor
The caller has the lock on objects.
cancelAndFlush in class AbstractObjectSpecificExecutor<O,O,Pair<java.lang.Runnable,java.lang.Runnable>>shutdownRequest - Whether this flush is caused by a AbstractObjectSpecificExecutor.shutdownNow(). In this case
all work has to be aborted, even the work pending after a flush.pending - The pending work that will not be executed due to abort or null if
running work should not be aborted.task - The task which to execute without any object work running.objectRunnables - The currently running work. This will either be aborted or awaited for
flushing.null in case no abortion is requested otherwise the managed objects
and the runtime data of the aborted work. Note that the runtime data may contain work
that is not cancelled by the flush. This depends on the runtime data.protected void restartPendingWork()
ObjectRunnable for executing this pending work.restartPendingWork in class AbstractObjectSpecificExecutor<O,O,Pair<java.lang.Runnable,java.lang.Runnable>>protected void executeShutdown(java.lang.Runnable shutdown)
AbstractObjectSpecificExecutorThreadPoolExecutor.shutdown() without abortion.
The caller has the lock on objects.
executeShutdown in class AbstractObjectSpecificExecutor<O,O,Pair<java.lang.Runnable,java.lang.Runnable>>shutdown - The task which to perform to shutdown.protected java.util.List<java.lang.Runnable> getOutstandingRunnables(java.util.Map<O,Pair<java.lang.Runnable,java.lang.Runnable>> outstandingWork)
AbstractObjectSpecificExecutorobjects.getOutstandingRunnables in class AbstractObjectSpecificExecutor<O,O,Pair<java.lang.Runnable,java.lang.Runnable>>outstandingWork - The pending work that has been aborted due to the immediate shutdown.