Package com.gengoai.concurrent
Class BlockingThreadPoolExecutor
- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- java.util.concurrent.ThreadPoolExecutor
-
- com.gengoai.concurrent.BlockingThreadPoolExecutor
-
- All Implemented Interfaces:
Executor
,ExecutorService
public class BlockingThreadPoolExecutor extends ThreadPoolExecutor
AThreadPoolExecutor
which blocks when the queue of items to be executed becomes full.- Author:
- David B. Bracewell
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.concurrent.ThreadPoolExecutor
ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.CallerRunsPolicy, ThreadPoolExecutor.DiscardOldestPolicy, ThreadPoolExecutor.DiscardPolicy
-
-
Constructor Summary
Constructors Constructor Description BlockingThreadPoolExecutor(int corePoolSize, int maximumPoolSize, int maxQueueSize)
Creates an executor with a given core and max pool size and maximum number of items to have waiting in the queue.BlockingThreadPoolExecutor(int corePoolSize, int maximumPoolSize, int maxQueueSize, long keepAliveTime, TimeUnit unit)
Creates an executor with a given core and max pool size and maximum number of items to have waiting in the queue.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
afterExecute(Runnable r, Throwable t)
void
awaitTermination()
Awaits termination of the threadsvoid
execute(Runnable command)
int
tasksInProgress()
-
Methods inherited from class java.util.concurrent.ThreadPoolExecutor
allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, beforeExecute, 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 Detail
-
BlockingThreadPoolExecutor
public BlockingThreadPoolExecutor(int corePoolSize, int maximumPoolSize, int maxQueueSize)
Creates an executor with a given core and max pool size and maximum number of items to have waiting in the queue. All threads will execute until completion or failure.- Parameters:
corePoolSize
- core pool sizemaximumPoolSize
- max pools sizemaxQueueSize
- max number of items to have waiting (good for memory)
-
BlockingThreadPoolExecutor
public BlockingThreadPoolExecutor(int corePoolSize, int maximumPoolSize, int maxQueueSize, long keepAliveTime, TimeUnit unit)
Creates an executor with a given core and max pool size and maximum number of items to have waiting in the queue. All threads will execute until completion or the keep alive time runs out.- Parameters:
corePoolSize
- core pool sizemaximumPoolSize
- max pools sizemaxQueueSize
- max number of items to have waiting (good for memory)keepAliveTime
- the amount of time to let the thread rununit
- the time unit associated with keepAliveTime
-
-
Method Detail
-
tasksInProgress
public int tasksInProgress()
- Returns:
- The number of tasks in progress
-
execute
public void execute(Runnable command)
- Specified by:
execute
in interfaceExecutor
- Overrides:
execute
in classThreadPoolExecutor
-
afterExecute
protected void afterExecute(Runnable r, Throwable t)
- Overrides:
afterExecute
in classThreadPoolExecutor
-
awaitTermination
public void awaitTermination() throws InterruptedException
Awaits termination of the threads- Throws:
InterruptedException
- The executor was interrupted
-
-