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.ThreadPoolExecutor
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
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 void
afterExecute(java.lang.Runnable task, java.lang.Throwable exc)
Process task completionvoid
execute(java.lang.Runnable task)
Execute a taskint
getCorePoolSize()
Return the core pool sizeint
getMaximumPoolSize()
Return the maximum pool sizevoid
setCorePoolSize(int coreSize)
Set the core pool sizevoid
setMaximumPoolSize(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:
getCorePoolSize
in classjava.util.concurrent.ThreadPoolExecutor
- Returns:
- Core pool size
-
setCorePoolSize
public void setCorePoolSize(int coreSize)
Set the core pool size- Overrides:
setCorePoolSize
in classjava.util.concurrent.ThreadPoolExecutor
- Parameters:
coreSize
- Core pool size
-
getMaximumPoolSize
public int getMaximumPoolSize()
Return the maximum pool size- Overrides:
getMaximumPoolSize
in classjava.util.concurrent.ThreadPoolExecutor
- Returns:
- Maximum pool size
-
setMaximumPoolSize
public void setMaximumPoolSize(int maxSize)
Set the maximum pool size- Overrides:
setMaximumPoolSize
in classjava.util.concurrent.ThreadPoolExecutor
- Parameters:
maxSize
- Maximum pool size
-
execute
public void execute(java.lang.Runnable task) throws java.util.concurrent.RejectedExecutionException
Execute a task- Specified by:
execute
in interfacejava.util.concurrent.Executor
- Overrides:
execute
in 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.RejectedExecutionException
Submit a task for execution- Specified by:
submit
in interfacejava.util.concurrent.ExecutorService
- Overrides:
submit
in 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.RejectedExecutionException
Submit a task for execution- Specified by:
submit
in interfacejava.util.concurrent.ExecutorService
- Overrides:
submit
in 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.RejectedExecutionException
Submit a task for execution- Specified by:
submit
in interfacejava.util.concurrent.ExecutorService
- Overrides:
submit
in 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:
afterExecute
in classjava.util.concurrent.ThreadPoolExecutor
- Parameters:
task
- Runnable taskexc
- Thrown exception
-
-