Package nxt.util
Class QueuedThreadPool
- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- java.util.concurrent.ThreadPoolExecutor
-
- nxt.util.QueuedThreadPool
-
- All Implemented Interfaces:
java.util.concurrent.Executor,java.util.concurrent.ExecutorService
public class QueuedThreadPool extends java.util.concurrent.ThreadPoolExecutorQueuedThreadPool 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
java.util.concurrent.ThreadPoolExecutor.AbortPolicy, java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy, java.util.concurrent.ThreadPoolExecutor.DiscardOldestPolicy, java.util.concurrent.ThreadPoolExecutor.DiscardPolicy
-
-
Constructor Summary
Constructors Constructor Description QueuedThreadPool(int coreSize, int maxSize)Create the queued thread pool
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidafterExecute(java.lang.Runnable task, java.lang.Throwable exc)Process task completionvoidexecute(java.lang.Runnable task)Execute a taskintgetCorePoolSize()Return the core pool sizeintgetMaximumPoolSize()Return the maximum pool sizevoidsetCorePoolSize(int coreSize)Set the core pool sizevoidsetMaximumPoolSize(int maxSize)Set the maximum pool sizejava.util.concurrent.Future<?>submit(java.lang.Runnable task)Submit a task for execution<T> java.util.concurrent.Future<T>submit(java.lang.Runnable task, T result)Submit a task for execution<T> java.util.concurrent.Future<T>submit(java.util.concurrent.Callable<T> callable)Submit a task for execution-
Methods 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, toString
-
-
-
-
Method Detail
-
getCorePoolSize
public int getCorePoolSize()
Return the core pool size- Overrides:
getCorePoolSizein classjava.util.concurrent.ThreadPoolExecutor- Returns:
- Core pool size
-
setCorePoolSize
public void setCorePoolSize(int coreSize)
Set the core pool size- Overrides:
setCorePoolSizein classjava.util.concurrent.ThreadPoolExecutor- Parameters:
coreSize- Core pool size
-
getMaximumPoolSize
public int getMaximumPoolSize()
Return the maximum pool size- Overrides:
getMaximumPoolSizein classjava.util.concurrent.ThreadPoolExecutor- Returns:
- Maximum pool size
-
setMaximumPoolSize
public void setMaximumPoolSize(int maxSize)
Set the maximum pool size- Overrides:
setMaximumPoolSizein classjava.util.concurrent.ThreadPoolExecutor- Parameters:
maxSize- Maximum pool size
-
execute
public void execute(java.lang.Runnable task) throws java.util.concurrent.RejectedExecutionExceptionExecute a task- Specified by:
executein interfacejava.util.concurrent.Executor- Overrides:
executein classjava.util.concurrent.ThreadPoolExecutor- Parameters:
task- Task- Throws:
java.util.concurrent.RejectedExecutionException- Unable to execute task
-
submit
public java.util.concurrent.Future<?> submit(java.lang.Runnable task) throws java.util.concurrent.RejectedExecutionExceptionSubmit a task for execution- Specified by:
submitin interfacejava.util.concurrent.ExecutorService- Overrides:
submitin classjava.util.concurrent.AbstractExecutorService- Parameters:
task- Runnable task- Returns:
- Future representing the task
- Throws:
java.util.concurrent.RejectedExecutionException- Unable to execute task
-
submit
public <T> java.util.concurrent.Future<T> submit(java.lang.Runnable task, T result) throws java.util.concurrent.RejectedExecutionExceptionSubmit a task for execution- Specified by:
submitin interfacejava.util.concurrent.ExecutorService- Overrides:
submitin classjava.util.concurrent.AbstractExecutorService- Type Parameters:
T- Result type- Parameters:
task- Runnable taskresult- Result returned when task completes- Returns:
- Future representing the task result
- Throws:
java.util.concurrent.RejectedExecutionException- Unable to execute task
-
submit
public <T> java.util.concurrent.Future<T> submit(java.util.concurrent.Callable<T> callable) throws java.util.concurrent.RejectedExecutionExceptionSubmit a task for execution- Specified by:
submitin interfacejava.util.concurrent.ExecutorService- Overrides:
submitin classjava.util.concurrent.AbstractExecutorService- Type Parameters:
T- Result type- Parameters:
callable- Callable task- Returns:
- Future representing the task
- Throws:
java.util.concurrent.RejectedExecutionException- Unable to execute task
-
afterExecute
protected void afterExecute(java.lang.Runnable task, java.lang.Throwable exc)Process task completion- Overrides:
afterExecutein classjava.util.concurrent.ThreadPoolExecutor- Parameters:
task- Runnable taskexc- Thrown exception
-
-