Class AbstractPipeliningExecutor<O,P>
- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- java.util.concurrent.ThreadPoolExecutor
-
- de.aristaflow.adept2.util.threading.AFThreadPoolExecutor
-
- de.aristaflow.adept2.util.threading.AbstractPipeliningExecutor<O,P>
-
- Type Parameters:
O
- The type of object for which work is registered.P
- The type identifying a pipeline. This can be the same as <O> or an appropriate hash value for the registered object.
- All Implemented Interfaces:
Executor
,ExecutorService
- Direct Known Subclasses:
LimitedPipelineExecutor
,UnlimitedPipelineExecutor
@Deprecated public abstract class AbstractPipeliningExecutor<O,P> extends AFThreadPoolExecutor
Deprecated.UseAbstractPipeliningExecutor
instead.A thread pool executor that accepts work for specific objects and executing the work for each object serial but work for different objects parallel (or at least concurrently).
While this thread pool executor can be used just like anyThreadPoolExecutor
, it behaves differently when submitting a runnable together with an object. In this case all runnables submitted for an object will be executed in the order they arrive. This is similar to having a pipeline for each object. The amount of pipelines is bound to the maximum amount of threads in the thread pool. This prevents starving of a pipeline due to the other pipelines being never empty.Note that pipelines are not assigned to one thread. As long as there is work in a pipeline, it will be executed by the same thread. As soon as a pipeline is empty, new work may be done by a different thread.
- Author:
- Ulrich Kreher, Kevin Goeser
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.concurrent.ThreadPoolExecutor
ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.CallerRunsPolicy, ThreadPoolExecutor.DiscardOldestPolicy, ThreadPoolExecutor.DiscardPolicy
-
-
Field Summary
Fields Modifier and Type Field Description protected AtomicInteger
abortCount
Deprecated.A counter for all flushs that aborted pending work.protected AtomicInteger
flushPending
Deprecated.A counter for pending flushs.protected Logger
logger
Deprecated.The logger for log messages, especially runtime exception occurring when executing work.protected Map<P,Pair<PipelineRunnable<P>,Queue<Runnable>>>
pipelines
Deprecated.All existing pipelines and the corresponding runnables.protected AtomicBoolean
shutdownPending
Deprecated.Whether a shutdown has been requested.-
Fields inherited from class de.aristaflow.adept2.util.threading.AFThreadPoolExecutor
activeThreads, completedTasks, HYSTERESIS, submittedTasks
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractPipeliningExecutor(int limit, Adept2ThreadFactory threadFactory)
Deprecated.Creates a new thread pool executor with the designated number of pipelines and threads for different objects using the designate thread factory for creating threads.protected
AbstractPipeliningExecutor(Adept2ThreadFactory threadFactory)
Deprecated.Creates a new thread pool executor with an unlimited amount of pipelines for different objects using the designate thread factory for creating threads.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
execute(O object, Runnable task)
Deprecated.Executes the designated task for the designated object.Map<P,Queue<Runnable>>
flushAndExecute(boolean abortPending, Runnable task)
Deprecated.Flushes all pipelines and executes the designated task.protected Map<P,Queue<Runnable>>
flushAndExecuteUnchecked(boolean abortPending, Runnable task)
Deprecated.The same asflushAndExecute(boolean, Runnable)
but without the check for a pending shutdown.protected abstract P
getPipelineFor(O object)
Deprecated.Gets the identifier determining the pipeline for the designated object accordingly to the limit of the number of pipelines.boolean
isShutdown()
Deprecated.protected boolean
restartPipelines(boolean abortedPending)
Deprecated.Restarts the pipelines after a flush.void
shutdown()
Deprecated.Shutting down will reject new work (normal or flushing).List<Runnable>
shutdownNow()
Deprecated.This shutdown will reject new work (normal or flushing) and abort the current work except of pending flushs.Future<?>
submit(O object, Runnable task)
Deprecated.Submits the designated task for the designated object.<T> Future<T>
submit(O object, Callable<T> task)
Deprecated.Submits the designated task for the designated object.<T> Pair<Future<T>,Map<P,Queue<Runnable>>>
submitAndFlush(boolean abortPending, Callable<T> task)
Deprecated.Submits the designated task and flushes all pipelines.-
Methods inherited from class de.aristaflow.adept2.util.threading.AFThreadPoolExecutor
afterExecute, beforeExecute, execute, logPoolStatistics, newTaskFor, newTaskFor, recalculateLogLimits, setCorePoolSize, setLogExecuteCallStack, setMaximumPoolSize, updateQueueLimit
-
Methods inherited from class java.util.concurrent.ThreadPoolExecutor
allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, finalize, getActiveCount, getCompletedTaskCount, getCorePoolSize, getKeepAliveTime, getLargestPoolSize, getMaximumPoolSize, getPoolSize, getQueue, getRejectedExecutionHandler, getTaskCount, getThreadFactory, isTerminated, isTerminating, prestartAllCoreThreads, prestartCoreThread, purge, remove, setKeepAliveTime, setRejectedExecutionHandler, setThreadFactory, terminated, toString
-
-
-
-
Field Detail
-
pipelines
protected final Map<P,Pair<PipelineRunnable<P>,Queue<Runnable>>> pipelines
Deprecated.All existing pipelines and the corresponding runnables.
-
flushPending
protected final AtomicInteger flushPending
Deprecated.A counter for pending flushs. With this the running pipelines will be terminated/suspended and concurrent flushs will be synchronised.
-
abortCount
protected final AtomicInteger abortCount
Deprecated.A counter for all flushs that aborted pending work.
-
shutdownPending
protected final AtomicBoolean shutdownPending
Deprecated.Whether a shutdown has been requested.
-
logger
protected final Logger logger
Deprecated.The logger for log messages, especially runtime exception occurring when executing work.
-
-
Constructor Detail
-
AbstractPipeliningExecutor
protected AbstractPipeliningExecutor(Adept2ThreadFactory threadFactory)
Deprecated.Creates a new thread pool executor with an unlimited amount of pipelines for different objects using the designate thread factory for creating threads. The threads will stay idle for 60 seconds before they terminate.- Parameters:
threadFactory
- The factory to use when the executor creates a new thread.
-
AbstractPipeliningExecutor
protected AbstractPipeliningExecutor(int limit, Adept2ThreadFactory threadFactory)
Deprecated.Creates a new thread pool executor with the designated number of pipelines and threads for different objects using the designate thread factory for creating threads. The threads will stay idle for 60 seconds before they terminate.- Parameters:
limit
- The maximum number of threads allowed in the pool and also the maximum number of pipelines.threadFactory
- The factory to use when the executor creates a new thread.
-
-
Method Detail
-
execute
public void execute(O object, Runnable task)
Deprecated.Executes the designated task for the designated object. If several tasks are to be executed for the same object, these tasks will be executed one after the other in the order they arrived.- Parameters:
object
- The object for which to execute the designated task.task
- The task which to execute.- Throws:
RejectedExecutionException
- if the executor has been shut down.- See Also:
AFThreadPoolExecutor.execute(Runnable)
-
flushAndExecute
public Map<P,Queue<Runnable>> flushAndExecute(boolean abortPending, Runnable task)
Deprecated.Flushes all pipelines and executes the designated task. When aborting, all registered work will be removed and returned. Otherwisenull
will be returned and the pipelines will restart work after the designated task has been executed.
This method can be called concurrently. It is ensured that all concurrent flushs will be executed before the pipelines will restart. The tasks of concurrent flushs will be executed concurrently!- Parameters:
abortPending
- Whether the present work should be cancelled. In this case the corresponding runnables will be returned.task
- The task which to execute without any pipeline running.- Returns:
null
in case no abortion is requested, otherwise the pipelines and the aborted work.- Throws:
RejectedExecutionException
- if the executor has been shut down.
-
flushAndExecuteUnchecked
protected Map<P,Queue<Runnable>> flushAndExecuteUnchecked(boolean abortPending, Runnable task)
Deprecated.The same asflushAndExecute(boolean, Runnable)
but without the check for a pending shutdown. This is required for the shutdown procedure.- Parameters:
abortPending
- Whether the present work should be cancelled. In this case the corresponding runnables will be returned.task
- The task which to execute without any pipeline running.- Returns:
null
in case no abortion is requested, otherwise the pipelines and the aborted work.- Throws:
RejectedExecutionException
- if the executor has been shut down.
-
submit
public Future<?> submit(O object, Runnable task)
Deprecated.Submits the designated task for the designated object. If several tasks are to be executed for the same object, these tasks will be executed one after the other in the order they arrived.- Parameters:
object
- The object for which to execute the designated task.task
- The task which to execute.- Returns:
- A
Future
representing pending completion of the task - Throws:
RejectedExecutionException
- if the executor has been shut down.- See Also:
AbstractExecutorService.submit(Runnable)
-
submit
public <T> Future<T> submit(O object, Callable<T> task)
Deprecated.Submits the designated task for the designated object. If several tasks are to be executed for the same object, these tasks will be executed one after the other in the order they arrived.- Parameters:
object
- The object for which to execute the designated task.task
- The task which to execute.- Returns:
- A
Future
representing pending completion of the task - Throws:
RejectedExecutionException
- if the executor has been shut down.- See Also:
AbstractExecutorService.submit(Callable)
-
submitAndFlush
public <T> Pair<Future<T>,Map<P,Queue<Runnable>>> submitAndFlush(boolean abortPending, Callable<T> task)
Deprecated.Submits the designated task and flushes all pipelines. When aborting, all registered work will be removed and returned. Otherwisenull
will be returned and the pipelines will restart work after the designated task has been executed.
This method can be called concurrently. It is ensured that all concurrent flushs will be executed before the pipelines will restart. The tasks of concurrent flushs will be executed concurrently!- Parameters:
abortPending
- Whether the present work should be cancelled. In this case the corresponding runnables will be returned.task
- The task which to execute without any pipeline running.- Returns:
- A pair containing the future representing the designated and as
second element either
null
in case no abortion is requested or the pipelines and the aborted work. - Throws:
RejectedExecutionException
- if the executor has been shut down.- See Also:
flushAndExecute(boolean, Runnable)
-
restartPipelines
protected boolean restartPipelines(boolean abortedPending)
Deprecated.Restarts the pipelines after a flush. If there are several concurrent flushs the pipelines will be started after the last flush.- Parameters:
abortedPending
- Whether the flush leading to this restart has aborted pending work.- Returns:
- Whether the pipelines have been restarted. Otherwise there are concurrent flushs or the executor has been shut down.
-
shutdown
public void shutdown()
Deprecated.Shutting down will reject new work (normal or flushing). But the current work may terminate. If there is currently a flush pending, the actual shutdown will wait until the suppressed work has been executed.- Specified by:
shutdown
in interfaceExecutorService
- Overrides:
shutdown
in classThreadPoolExecutor
-
shutdownNow
public List<Runnable> shutdownNow()
Deprecated.This shutdown will reject new work (normal or flushing) and abort the current work except of pending flushs.- Specified by:
shutdownNow
in interfaceExecutorService
- Overrides:
shutdownNow
in classThreadPoolExecutor
-
isShutdown
public boolean isShutdown()
Deprecated.- Specified by:
isShutdown
in interfaceExecutorService
- Overrides:
isShutdown
in classThreadPoolExecutor
-
getPipelineFor
protected abstract P getPipelineFor(O object)
Deprecated.Gets the identifier determining the pipeline for the designated object accordingly to the limit of the number of pipelines.- Parameters:
object
- The object for which to determine the pipeline.- Returns:
- The identifier determining the pipeline for the designated object.
-
-