public class OrderedThreadPoolExecutor
extends java.util.concurrent.ThreadPoolExecutor
ThreadPoolExecutor that maintains the order of IoEvents.
If you don't need to maintain the order of events per session, please use
UnorderedThreadPoolExecutor.
| Modifier and Type | Class and Description |
|---|---|
private class |
OrderedThreadPoolExecutor.SessionTasksQueue
A class used to store the ordered list of events to be processed by the
session, and the current task state.
|
private class |
OrderedThreadPoolExecutor.Worker |
java.util.concurrent.ThreadPoolExecutor.AbortPolicy, java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy, java.util.concurrent.ThreadPoolExecutor.DiscardOldestPolicy, java.util.concurrent.ThreadPoolExecutor.DiscardPolicy| Modifier and Type | Field and Description |
|---|---|
private long |
completedTaskCount |
private static int |
DEFAULT_INITIAL_THREAD_POOL_SIZE
A default value for the initial pool size
|
private static int |
DEFAULT_KEEP_ALIVE
A default value for the KeepAlive delay
|
private static int |
DEFAULT_MAX_THREAD_POOL
A default value for the maximum pool size
|
private IoEventQueueHandler |
eventQueueHandler |
private static IoSession |
EXIT_SIGNAL |
private java.util.concurrent.atomic.AtomicInteger |
idleWorkers |
private int |
largestPoolSize |
private static org.slf4j.Logger |
LOGGER
A logger for this class (commented as it breaks MDCFlter tests)
|
private boolean |
shutdown |
private AttributeKey |
TASKS_QUEUE
A key stored into the session's attribute for the event tasks being queued
|
private java.util.concurrent.BlockingQueue<IoSession> |
waitingSessions
A queue used to store the available sessions
|
private java.util.Set<OrderedThreadPoolExecutor.Worker> |
workers |
| Constructor and Description |
|---|
OrderedThreadPoolExecutor()
Creates a default ThreadPool, with default values :
- minimum pool size is 0
- maximum pool size is 16
- keepAlive set to 30 seconds
- A default ThreadFactory
- All events are accepted
|
OrderedThreadPoolExecutor(int maximumPoolSize)
Creates a default ThreadPool, with default values :
- minimum pool size is 0
- keepAlive set to 30 seconds
- A default ThreadFactory
- All events are accepted
|
OrderedThreadPoolExecutor(int corePoolSize,
int maximumPoolSize)
Creates a default ThreadPool, with default values :
- keepAlive set to 30 seconds
- A default ThreadFactory
- All events are accepted
|
OrderedThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
java.util.concurrent.TimeUnit unit)
Creates a default ThreadPool, with default values :
- A default ThreadFactory
- All events are accepted
|
OrderedThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
java.util.concurrent.TimeUnit unit,
IoEventQueueHandler eventQueueHandler)
Creates a default ThreadPool, with default values :
- A default ThreadFactory
|
OrderedThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
java.util.concurrent.TimeUnit unit,
java.util.concurrent.ThreadFactory threadFactory)
Creates a default ThreadPool, with default values :
- A default ThreadFactory
|
OrderedThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
java.util.concurrent.TimeUnit unit,
java.util.concurrent.ThreadFactory threadFactory,
IoEventQueueHandler eventQueueHandler)
Creates a new instance of a OrderedThreadPoolExecutor.
|
| Modifier and Type | Method and Description |
|---|---|
private void |
addWorker()
Add a new thread to execute a task, if needed and possible.
|
private void |
addWorkerIfNecessary()
Add a new Worker only if there are no idle worker.
|
boolean |
awaitTermination(long timeout,
java.util.concurrent.TimeUnit unit) |
private void |
checkTaskType(java.lang.Runnable task) |
void |
execute(java.lang.Runnable task) |
int |
getActiveCount() |
long |
getCompletedTaskCount() |
int |
getCorePoolSize() |
int |
getLargestPoolSize() |
int |
getMaximumPoolSize() |
int |
getPoolSize() |
java.util.concurrent.BlockingQueue<java.lang.Runnable> |
getQueue() |
IoEventQueueHandler |
getQueueHandler() |
private OrderedThreadPoolExecutor.SessionTasksQueue |
getSessionTasksQueue(IoSession session)
Get the session's tasks queue.
|
long |
getTaskCount() |
boolean |
isShutdown() |
boolean |
isTerminated() |
boolean |
isTerminating() |
int |
prestartAllCoreThreads() |
boolean |
prestartCoreThread() |
private void |
print(java.util.Queue<java.lang.Runnable> queue,
IoEvent event)
A Helper class used to print the list of events being queued.
|
void |
purge() |
private void |
rejectTask(java.lang.Runnable task) |
boolean |
remove(java.lang.Runnable task) |
private void |
removeWorker() |
void |
setCorePoolSize(int corePoolSize) |
void |
setMaximumPoolSize(int maximumPoolSize) |
void |
setRejectedExecutionHandler(java.util.concurrent.RejectedExecutionHandler handler) |
void |
shutdown() |
java.util.List<java.lang.Runnable> |
shutdownNow() |
afterExecute, allowCoreThreadTimeOut, allowsCoreThreadTimeOut, beforeExecute, finalize, getKeepAliveTime, getRejectedExecutionHandler, getThreadFactory, setKeepAliveTime, setThreadFactory, terminated, toStringprivate static org.slf4j.Logger LOGGER
private static final int DEFAULT_INITIAL_THREAD_POOL_SIZE
private static final int DEFAULT_MAX_THREAD_POOL
private static final int DEFAULT_KEEP_ALIVE
private static final IoSession EXIT_SIGNAL
private final AttributeKey TASKS_QUEUE
private final java.util.concurrent.BlockingQueue<IoSession> waitingSessions
private final java.util.Set<OrderedThreadPoolExecutor.Worker> workers
private volatile int largestPoolSize
private final java.util.concurrent.atomic.AtomicInteger idleWorkers
private long completedTaskCount
private volatile boolean shutdown
private final IoEventQueueHandler eventQueueHandler
public OrderedThreadPoolExecutor()
public OrderedThreadPoolExecutor(int maximumPoolSize)
maximumPoolSize - The maximum pool sizepublic OrderedThreadPoolExecutor(int corePoolSize,
int maximumPoolSize)
corePoolSize - The initial pool sizePoolSizemaximumPoolSize - The maximum pool sizepublic OrderedThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
java.util.concurrent.TimeUnit unit)
corePoolSize - The initial pool sizePoolSizemaximumPoolSize - The maximum pool sizekeepAliveTime - Default duration for a threadunit - Time unit used for the keepAlive valuepublic OrderedThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
java.util.concurrent.TimeUnit unit,
IoEventQueueHandler eventQueueHandler)
corePoolSize - The initial pool sizePoolSizemaximumPoolSize - The maximum pool sizekeepAliveTime - Default duration for a threadunit - Time unit used for the keepAlive valueeventQueueHandler - The queue used to store eventspublic OrderedThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
java.util.concurrent.TimeUnit unit,
java.util.concurrent.ThreadFactory threadFactory)
corePoolSize - The initial pool sizePoolSizemaximumPoolSize - The maximum pool sizekeepAliveTime - Default duration for a threadunit - Time unit used for the keepAlive valuethreadFactory - The factory used to create threadspublic OrderedThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
java.util.concurrent.TimeUnit unit,
java.util.concurrent.ThreadFactory threadFactory,
IoEventQueueHandler eventQueueHandler)
corePoolSize - The initial pool sizePoolSizemaximumPoolSize - The maximum pool sizekeepAliveTime - Default duration for a threadunit - Time unit used for the keepAlive valuethreadFactory - The factory used to create threadseventQueueHandler - The queue used to store eventsprivate OrderedThreadPoolExecutor.SessionTasksQueue getSessionTasksQueue(IoSession session)
public IoEventQueueHandler getQueueHandler()
public void setRejectedExecutionHandler(java.util.concurrent.RejectedExecutionHandler handler)
setRejectedExecutionHandler in class java.util.concurrent.ThreadPoolExecutorprivate void addWorker()
private void addWorkerIfNecessary()
private void removeWorker()
public int getMaximumPoolSize()
getMaximumPoolSize in class java.util.concurrent.ThreadPoolExecutorpublic void setMaximumPoolSize(int maximumPoolSize)
setMaximumPoolSize in class java.util.concurrent.ThreadPoolExecutorpublic boolean awaitTermination(long timeout,
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException
awaitTermination in interface java.util.concurrent.ExecutorServiceawaitTermination in class java.util.concurrent.ThreadPoolExecutorjava.lang.InterruptedExceptionpublic boolean isShutdown()
isShutdown in interface java.util.concurrent.ExecutorServiceisShutdown in class java.util.concurrent.ThreadPoolExecutorpublic boolean isTerminated()
isTerminated in interface java.util.concurrent.ExecutorServiceisTerminated in class java.util.concurrent.ThreadPoolExecutorpublic void shutdown()
shutdown in interface java.util.concurrent.ExecutorServiceshutdown in class java.util.concurrent.ThreadPoolExecutorpublic java.util.List<java.lang.Runnable> shutdownNow()
shutdownNow in interface java.util.concurrent.ExecutorServiceshutdownNow in class java.util.concurrent.ThreadPoolExecutorprivate void print(java.util.Queue<java.lang.Runnable> queue,
IoEvent event)
public void execute(java.lang.Runnable task)
execute in interface java.util.concurrent.Executorexecute in class java.util.concurrent.ThreadPoolExecutorprivate void rejectTask(java.lang.Runnable task)
private void checkTaskType(java.lang.Runnable task)
public int getActiveCount()
getActiveCount in class java.util.concurrent.ThreadPoolExecutorpublic long getCompletedTaskCount()
getCompletedTaskCount in class java.util.concurrent.ThreadPoolExecutorpublic int getLargestPoolSize()
getLargestPoolSize in class java.util.concurrent.ThreadPoolExecutorpublic int getPoolSize()
getPoolSize in class java.util.concurrent.ThreadPoolExecutorpublic long getTaskCount()
getTaskCount in class java.util.concurrent.ThreadPoolExecutorpublic boolean isTerminating()
isTerminating in class java.util.concurrent.ThreadPoolExecutorpublic int prestartAllCoreThreads()
prestartAllCoreThreads in class java.util.concurrent.ThreadPoolExecutorpublic boolean prestartCoreThread()
prestartCoreThread in class java.util.concurrent.ThreadPoolExecutorpublic java.util.concurrent.BlockingQueue<java.lang.Runnable> getQueue()
getQueue in class java.util.concurrent.ThreadPoolExecutorpublic void purge()
purge in class java.util.concurrent.ThreadPoolExecutorpublic boolean remove(java.lang.Runnable task)
remove in class java.util.concurrent.ThreadPoolExecutorpublic int getCorePoolSize()
getCorePoolSize in class java.util.concurrent.ThreadPoolExecutorpublic void setCorePoolSize(int corePoolSize)
setCorePoolSize in class java.util.concurrent.ThreadPoolExecutor