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 aPausableThreadPoolExecutorwith core/maximum pool size set to one.PausableThreadPoolExecutor(String poolPrefix, int corePoolSize, int maximumPoolSize) Create aPausableThreadPoolExecutorwith specified parameters.PausableThreadPoolExecutor(String poolPrefix, int corePoolSize, int maximumPoolSize, int queueSize) Create aPausableThreadPoolExecutorwith specified parameters.PausableThreadPoolExecutor(String poolPrefix, int corePoolSize, int maximumPoolSize, int queueSize, long keepAliveTime, TimeUnit unit, Consumer<Runnable> afterExecuteFunc) Create aPausableThreadPoolExecutorwith specified parameters.PausableThreadPoolExecutor(String poolPrefix, int corePoolSize, int maximumPoolSize, int queueSize, Consumer<Runnable> afterExecuteFunc) Create aPausableThreadPoolExecutorwith specified parameters.PausableThreadPoolExecutor(String poolPrefix, int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory, Consumer<Runnable> afterExecuteFunc) Create aPausableThreadPoolExecutorwith specified parameters.PausableThreadPoolExecutor(String poolPrefix, int corePoolSize, int maximumPoolSize, Consumer<Runnable> afterExecuteFunc) Create aPausableThreadPoolExecutorwith specified parameters. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidafterExecute(Runnable r, Throwable t) protected voidbeforeExecute(Thread t, Runnable r) booleanisPaused()Check if thisPausableThreadPoolExecutoris paused.voidpause()Pause the execution of thisPausableThreadPoolExecutor.voidresume()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, toStringMethods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor, submit, submit, submit
-
Constructor Details
-
PausableThreadPoolExecutor
public PausableThreadPoolExecutor()Create aPausableThreadPoolExecutorwith core/maximum pool size set to one. -
PausableThreadPoolExecutor
Create aPausableThreadPoolExecutorwith 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 aPausableThreadPoolExecutorwith 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 aPausableThreadPoolExecutorwith 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 aPausableThreadPoolExecutorwith 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 aPausableThreadPoolExecutorwith 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 thekeepAliveTimeargumentafterExecuteFunc- 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 aPausableThreadPoolExecutorwith 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 thekeepAliveTimeargumentworkQueue- 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:
beforeExecutein classThreadPoolExecutor
-
afterExecute
- Overrides:
afterExecutein 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 thisPausableThreadPoolExecutoris paused.- Returns:
- whether this
PausableThreadPoolExecutoris paused.
-