Package nxt.util
Class QueuedThreadPool
java.lang.Object
java.util.concurrent.AbstractExecutorService
java.util.concurrent.ThreadPoolExecutor
nxt.util.QueuedThreadPool
- All Implemented Interfaces:
Executor,ExecutorService
QueuedThreadPool creates threads to process requests until the maximum pool
size is reached. Additional requests are queued until a thread becomes
available. Threads that are idle for 60 seconds are terminated if the
pool size is greater than the core size.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.concurrent.ThreadPoolExecutor
ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.CallerRunsPolicy, ThreadPoolExecutor.DiscardOldestPolicy, ThreadPoolExecutor.DiscardPolicy -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidafterExecute(Runnable task, Throwable exc) Process task completionvoidExecute a taskintReturn the core pool sizeintReturn the maximum pool sizevoidsetCorePoolSize(int coreSize) Set the core pool sizevoidsetMaximumPoolSize(int maxSize) Set the maximum pool sizeFuture<?>Submit a task for execution<T> Future<T>Submit a task for execution<T> Future<T>Submit a task for executionMethods inherited from class java.util.concurrent.ThreadPoolExecutor
allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, beforeExecute, finalize, getActiveCount, getCompletedTaskCount, getKeepAliveTime, getLargestPoolSize, getPoolSize, getQueue, getRejectedExecutionHandler, getTaskCount, getThreadFactory, isShutdown, isTerminated, isTerminating, prestartAllCoreThreads, prestartCoreThread, purge, remove, setKeepAliveTime, setRejectedExecutionHandler, setThreadFactory, shutdown, shutdownNow, terminated, toStringMethods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor
-
Constructor Details
-
QueuedThreadPool
public QueuedThreadPool(int coreSize, int maxSize) Create the queued thread pool- Parameters:
coreSize- Core pool sizemaxSize- Maximum pool size
-
-
Method Details
-
getCorePoolSize
public int getCorePoolSize()Return the core pool size- Overrides:
getCorePoolSizein classThreadPoolExecutor- Returns:
- Core pool size
-
setCorePoolSize
public void setCorePoolSize(int coreSize) Set the core pool size- Overrides:
setCorePoolSizein classThreadPoolExecutor- Parameters:
coreSize- Core pool size
-
getMaximumPoolSize
public int getMaximumPoolSize()Return the maximum pool size- Overrides:
getMaximumPoolSizein classThreadPoolExecutor- Returns:
- Maximum pool size
-
setMaximumPoolSize
public void setMaximumPoolSize(int maxSize) Set the maximum pool size- Overrides:
setMaximumPoolSizein classThreadPoolExecutor- Parameters:
maxSize- Maximum pool size
-
execute
Execute a task- Specified by:
executein interfaceExecutor- Overrides:
executein classThreadPoolExecutor- Parameters:
task- Task- Throws:
RejectedExecutionException- Unable to execute task
-
submit
Submit a task for execution- Specified by:
submitin interfaceExecutorService- Overrides:
submitin classAbstractExecutorService- Parameters:
task- Runnable task- Returns:
- Future representing the task
- Throws:
RejectedExecutionException- Unable to execute task
-
submit
Submit a task for execution- Specified by:
submitin interfaceExecutorService- Overrides:
submitin classAbstractExecutorService- Type Parameters:
T- Result type- Parameters:
task- Runnable taskresult- Result returned when task completes- Returns:
- Future representing the task result
- Throws:
RejectedExecutionException- Unable to execute task
-
submit
Submit a task for execution- Specified by:
submitin interfaceExecutorService- Overrides:
submitin classAbstractExecutorService- Type Parameters:
T- Result type- Parameters:
callable- Callable task- Returns:
- Future representing the task
- Throws:
RejectedExecutionException- Unable to execute task
-
afterExecute
Process task completion- Overrides:
afterExecutein classThreadPoolExecutor- Parameters:
task- Runnable taskexc- Thrown exception
-