Package org.kquiet.concurrent
Class PausableThreadPoolExecutor
java.lang.Object
java.util.concurrent.AbstractExecutorService
java.util.concurrent.ThreadPoolExecutor
org.kquiet.concurrent.PausableThreadPoolExecutor
- All Implemented Interfaces:
Executor
,ExecutorService
- Direct Known Subclasses:
PausablePriorityThreadPoolExecutor
Pausable
ThreadPoolExecutor
. This class is for internal use.- Author:
- Kimberly
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.concurrent.ThreadPoolExecutor
ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.CallerRunsPolicy, ThreadPoolExecutor.DiscardOldestPolicy, ThreadPoolExecutor.DiscardPolicy
-
Constructor Summary
ConstructorsConstructorDescriptionCreate aPausableThreadPoolExecutor
with core/maximum pool size set to one.PausableThreadPoolExecutor
(String poolPrefix, int corePoolSize, int maximumPoolSize) Create aPausableThreadPoolExecutor
with specified parameters.PausableThreadPoolExecutor
(String poolPrefix, int corePoolSize, int maximumPoolSize, int queueSize) Create aPausableThreadPoolExecutor
with specified parameters.PausableThreadPoolExecutor
(String poolPrefix, int corePoolSize, int maximumPoolSize, int queueSize, long keepAliveTime, TimeUnit unit, Consumer<Runnable> afterExecuteFunc) Create aPausableThreadPoolExecutor
with specified parameters.PausableThreadPoolExecutor
(String poolPrefix, int corePoolSize, int maximumPoolSize, int queueSize, Consumer<Runnable> afterExecuteFunc) Create aPausableThreadPoolExecutor
with specified parameters.PausableThreadPoolExecutor
(String poolPrefix, int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory, Consumer<Runnable> afterExecuteFunc) Create aPausableThreadPoolExecutor
with specified parameters.PausableThreadPoolExecutor
(String poolPrefix, int corePoolSize, int maximumPoolSize, Consumer<Runnable> afterExecuteFunc) Create aPausableThreadPoolExecutor
with specified parameters. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
afterExecute
(Runnable r, Throwable t) protected void
beforeExecute
(Thread t, Runnable r) boolean
isPaused()
Check if thisPausableThreadPoolExecutor
is paused.void
pause()
Pause the execution of thisPausableThreadPoolExecutor
.void
resume()
Resume the execution of thisPausableThreadPoolExecutor
.Methods inherited from class java.util.concurrent.ThreadPoolExecutor
allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, execute, finalize, getActiveCount, getCompletedTaskCount, getCorePoolSize, getKeepAliveTime, getLargestPoolSize, getMaximumPoolSize, getPoolSize, getQueue, getRejectedExecutionHandler, getTaskCount, getThreadFactory, isShutdown, isTerminated, isTerminating, prestartAllCoreThreads, prestartCoreThread, purge, remove, setCorePoolSize, setKeepAliveTime, setMaximumPoolSize, setRejectedExecutionHandler, setThreadFactory, shutdown, shutdownNow, terminated, toString
Methods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor, submit, submit, submit
-
Constructor Details
-
PausableThreadPoolExecutor
public PausableThreadPoolExecutor()Create aPausableThreadPoolExecutor
with core/maximum pool size set to one. -
PausableThreadPoolExecutor
Create aPausableThreadPoolExecutor
with specified parameters.- Parameters:
poolPrefix
- prefix name of thread poolcorePoolSize
- core pool sizemaximumPoolSize
- maximum pool size
-
PausableThreadPoolExecutor
public PausableThreadPoolExecutor(String poolPrefix, int corePoolSize, int maximumPoolSize, int queueSize) Create aPausableThreadPoolExecutor
with specified parameters.- Parameters:
poolPrefix
- prefix name of thread poolcorePoolSize
- core pool sizemaximumPoolSize
- maximum pool sizequeueSize
- the maximum queue size used for holding tasks before they are executed
-
PausableThreadPoolExecutor
public PausableThreadPoolExecutor(String poolPrefix, int corePoolSize, int maximumPoolSize, Consumer<Runnable> afterExecuteFunc) Create aPausableThreadPoolExecutor
with specified parameters.- Parameters:
poolPrefix
- prefix name of thread poolcorePoolSize
- core pool sizemaximumPoolSize
- maximum pool sizeafterExecuteFunc
- the function to execute after any task is executed
-
PausableThreadPoolExecutor
public PausableThreadPoolExecutor(String poolPrefix, int corePoolSize, int maximumPoolSize, int queueSize, Consumer<Runnable> afterExecuteFunc) Create aPausableThreadPoolExecutor
with specified parameters.- Parameters:
poolPrefix
- prefix name of thread poolcorePoolSize
- core pool sizemaximumPoolSize
- maximum pool sizequeueSize
- the maximum queue size used for holding tasks before they are executedafterExecuteFunc
- the function to execute after any task is executed
-
PausableThreadPoolExecutor
public PausableThreadPoolExecutor(String poolPrefix, int corePoolSize, int maximumPoolSize, int queueSize, long keepAliveTime, TimeUnit unit, Consumer<Runnable> afterExecuteFunc) Create aPausableThreadPoolExecutor
with specified parameters.- Parameters:
poolPrefix
- prefix name of thread poolcorePoolSize
- core pool sizemaximumPoolSize
- maximum pool sizequeueSize
- the maximum queue size used for holding tasks before they are executedkeepAliveTime
- when the number of threads is greater than the core, this is the maximum time that excess idle threads will wait for new tasks before terminating.unit
- the time unit for thekeepAliveTime
argumentafterExecuteFunc
- the function to execute after any task is executed
-
PausableThreadPoolExecutor
public PausableThreadPoolExecutor(String poolPrefix, int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory, Consumer<Runnable> afterExecuteFunc) Create aPausableThreadPoolExecutor
with specified parameters.- Parameters:
poolPrefix
- prefix name of thread poolcorePoolSize
- core pool sizemaximumPoolSize
- maximum pool sizekeepAliveTime
- when the number of threads is greater than the core, this is the maximum time that excess idle threads will wait for new tasks before terminating.unit
- the time unit for thekeepAliveTime
argumentworkQueue
- the queue used for holding tasks before they are executedthreadFactory
- the factory to use when the executor creates a new threadafterExecuteFunc
- the function to execute after any task is executed
-
-
Method Details
-
beforeExecute
- Overrides:
beforeExecute
in classThreadPoolExecutor
-
afterExecute
- Overrides:
afterExecute
in classThreadPoolExecutor
-
pause
public void pause()Pause the execution of thisPausableThreadPoolExecutor
. Any executing task is not affected. -
resume
public void resume()Resume the execution of thisPausableThreadPoolExecutor
. -
isPaused
public boolean isPaused()Check if thisPausableThreadPoolExecutor
is paused.- Returns:
- whether this
PausableThreadPoolExecutor
is paused.
-