public final class QueueExecutor extends java.util.concurrent.AbstractExecutorService implements BlockingExecutorService, BoundedQueueThreadPoolExecutorMBean, ShutdownListenable
| Modifier and Type | Class and Description |
|---|---|
private class |
QueueExecutor.Worker |
| Modifier and Type | Field and Description |
|---|---|
private boolean |
allowCoreThreadTimeout |
private boolean |
blocking |
private int |
coreThreads |
private java.util.concurrent.locks.Condition |
enqueueCondition |
private java.util.concurrent.Executor |
handoffExecutor |
private long |
keepAliveTime |
private java.util.concurrent.TimeUnit |
keepAliveTimeUnit |
private int |
largestPoolSize |
private java.util.concurrent.locks.Lock |
lock |
private static org.jboss.logging.Logger |
log |
private int |
maxThreads |
private java.util.Queue<java.lang.Runnable> |
queue |
private int |
rejectCount |
private java.util.concurrent.locks.Condition |
removeCondition |
private SimpleShutdownListenable |
shutdownListenable |
private boolean |
stop |
private DirectExecutor |
taskExecutor |
private int |
threadCount |
private java.util.concurrent.locks.Condition |
threadExitCondition |
private java.util.concurrent.ThreadFactory |
threadFactory |
private java.util.Set<java.lang.Thread> |
workers |
| Constructor and Description |
|---|
QueueExecutor(int coreThreads,
int maxThreads,
long keepAliveTime,
java.util.concurrent.TimeUnit keepAliveTimeUnit,
int queueLength,
java.util.concurrent.ThreadFactory threadFactory,
boolean blocking,
java.util.concurrent.Executor handoffExecutor)
Create a new instance.
|
QueueExecutor(int coreThreads,
int maxThreads,
long keepAliveTime,
java.util.concurrent.TimeUnit keepAliveTimeUnit,
java.util.Queue<java.lang.Runnable> queue,
java.util.concurrent.ThreadFactory threadFactory,
boolean blocking,
java.util.concurrent.Executor handoffExecutor)
Create a new instance.
|
QueueExecutor(int coreThreads,
int maxThreads,
long keepAliveTime,
java.util.concurrent.TimeUnit keepAliveTimeUnit,
java.util.Queue<java.lang.Runnable> queue,
java.util.concurrent.ThreadFactory threadFactory,
boolean blocking,
java.util.concurrent.Executor handoffExecutor,
DirectExecutor taskExecutor)
Create a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
<A> void |
addShutdownListener(EventListener<A> shutdownListener,
A attachment)
Add a shutdown listener.
|
boolean |
awaitTermination(long timeout,
java.util.concurrent.TimeUnit unit) |
void |
execute(java.lang.Runnable task)
Execute a task.
|
void |
executeBlocking(java.lang.Runnable task)
Execute a task, blocking until it can be accepted, or until the calling thread is interrupted.
|
void |
executeBlocking(java.lang.Runnable task,
long timeout,
java.util.concurrent.TimeUnit unit)
Execute a task, blocking until it can be accepted, a timeout elapses, or the calling thread is interrupted.
|
void |
executeNonBlocking(java.lang.Runnable task)
Execute a task, without blocking.
|
int |
getCoreThreads() |
int |
getCurrentThreadCount() |
java.util.concurrent.Executor |
getHandoffExecutor()
Get the handoff executor which is called when a task cannot be accepted immediately.
|
long |
getKeepAliveTime() |
int |
getLargestThreadCount() |
int |
getMaxThreads() |
int |
getQueueSize() |
int |
getRejectedCount() |
boolean |
isAllowCoreThreadTimeout() |
boolean |
isBlocking()
Determine whether this thread pool executor is set to block when a task cannot be accepted immediately.
|
boolean |
isShutdown() |
boolean |
isTerminated() |
private java.lang.Runnable |
pollTask() |
private void |
runTask(java.lang.Runnable task) |
void |
setAllowCoreThreadTimeout(boolean allowCoreThreadTimeout) |
void |
setBlocking(boolean blocking)
Set whether this thread pool executor should be set to block when a task cannot be accepted immediately.
|
void |
setCoreThreads(int coreThreads) |
void |
setHandoffExecutor(java.util.concurrent.Executor handoffExecutor)
Set the handoff executor which is called when a task cannot be accepted immediately.
|
void |
setKeepAliveTime(long milliseconds) |
void |
setKeepAliveTime(long keepAliveTime,
java.util.concurrent.TimeUnit keepAliveTimeUnit)
Set the keep-alive time to the given amount of time.
|
void |
setMaxThreads(int maxThreads) |
void |
shutdown() |
java.util.List<java.lang.Runnable> |
shutdownNow() |
private void |
startNewThread(java.lang.Runnable task) |
private java.lang.Runnable |
takeTask() |
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor, submit, submit, submitprivate static final org.jboss.logging.Logger log
private final SimpleShutdownListenable shutdownListenable
private final java.util.concurrent.locks.Lock lock
private final java.util.concurrent.locks.Condition enqueueCondition
private final java.util.concurrent.locks.Condition removeCondition
private final java.util.concurrent.locks.Condition threadExitCondition
private final java.util.concurrent.ThreadFactory threadFactory
private final DirectExecutor taskExecutor
private int coreThreads
private int maxThreads
private int largestPoolSize
private int rejectCount
private boolean allowCoreThreadTimeout
private long keepAliveTime
private java.util.concurrent.TimeUnit keepAliveTimeUnit
private boolean blocking
private java.util.concurrent.Executor handoffExecutor
private int threadCount
private java.util.Set<java.lang.Thread> workers
private boolean stop
private java.util.Queue<java.lang.Runnable> queue
public QueueExecutor(int coreThreads,
int maxThreads,
long keepAliveTime,
java.util.concurrent.TimeUnit keepAliveTimeUnit,
java.util.Queue<java.lang.Runnable> queue,
java.util.concurrent.ThreadFactory threadFactory,
boolean blocking,
java.util.concurrent.Executor handoffExecutor,
DirectExecutor taskExecutor)
coreThreads - the number of threads to create before enqueueing tasksmaxThreads - the maximum number of threads to createkeepAliveTime - the amount of time that an idle thread should remain activekeepAliveTimeUnit - the unit of time for keepAliveTimequeue - the queue to use for tasksthreadFactory - the thread factory to use for new threadsblocking - true if the executor should block when the queue is full and no threads are available, false to use the handoff executorhandoffExecutor - the executor which is called when blocking is disabled and a task cannot be accepted, or null to reject the tasktaskExecutor - the executor to use to execute taskspublic QueueExecutor(int coreThreads,
int maxThreads,
long keepAliveTime,
java.util.concurrent.TimeUnit keepAliveTimeUnit,
java.util.Queue<java.lang.Runnable> queue,
java.util.concurrent.ThreadFactory threadFactory,
boolean blocking,
java.util.concurrent.Executor handoffExecutor)
coreThreads - the number of threads to create before enqueueing tasksmaxThreads - the maximum number of threads to createkeepAliveTime - the amount of time that an idle thread should remain activekeepAliveTimeUnit - the unit of time for keepAliveTimequeue - the queue to use for tasksthreadFactory - the thread factory to use for new threadsblocking - true if the executor should block when the queue is full and no threads are available, false to use the handoff executorhandoffExecutor - the executor which is called when blocking is disabled and a task cannot be accepted, or null to reject the taskpublic QueueExecutor(int coreThreads,
int maxThreads,
long keepAliveTime,
java.util.concurrent.TimeUnit keepAliveTimeUnit,
int queueLength,
java.util.concurrent.ThreadFactory threadFactory,
boolean blocking,
java.util.concurrent.Executor handoffExecutor)
coreThreads - the number of threads to create before enqueueing tasksmaxThreads - the maximum number of threads to createkeepAliveTime - the amount of time that an idle thread should remain activekeepAliveTimeUnit - the unit of time for keepAliveTimequeueLength - the fixed queue length to use for tasksthreadFactory - the thread factory to use for new threadsblocking - true if the executor should block when the queue is full and no threads are available, false to use the handoff executorhandoffExecutor - the executor which is called when blocking is disabled and a task cannot be accepted, or null to reject the taskpublic void execute(java.lang.Runnable task)
throws java.util.concurrent.RejectedExecutionException
execute in interface java.util.concurrent.Executorexecute in interface BlockingExecutortask - the task to executejava.util.concurrent.RejectedExecutionException - when a task is rejected by the handoff executorStoppedExecutorException - when the executor is terminatingExecutionInterruptedException - when blocking is enabled and the current thread is interrupted before a task could be acceptedpublic void executeBlocking(java.lang.Runnable task)
throws java.util.concurrent.RejectedExecutionException,
java.lang.InterruptedException
executeBlocking in interface BlockingExecutortask - the task to submitStoppedExecutorException - if the executor was shut down before the task was acceptedThreadCreationException - if a thread could not be created for some reasonjava.util.concurrent.RejectedExecutionException - if execution is rejected for some other reasonjava.lang.InterruptedException - if the current thread was interrupted before the task could be acceptedjava.lang.NullPointerException - if command is nullpublic void executeBlocking(java.lang.Runnable task,
long timeout,
java.util.concurrent.TimeUnit unit)
throws java.util.concurrent.RejectedExecutionException,
java.lang.InterruptedException
executeBlocking in interface BlockingExecutortask - the task to submittimeout - the amount of time to waitunit - the unit of timeExecutionTimedOutException - if the timeout elapsed before a task could be acceptedStoppedExecutorException - if the executor was shut down before the task was acceptedThreadCreationException - if a thread could not be created for some reasonjava.util.concurrent.RejectedExecutionException - if execution is rejected for some other reasonjava.lang.InterruptedException - if the current thread was interrupted before the task could be acceptedjava.lang.NullPointerException - if command is nullpublic void executeNonBlocking(java.lang.Runnable task)
throws java.util.concurrent.RejectedExecutionException
executeNonBlocking in interface BlockingExecutortask - the task to submitStoppedExecutorException - if the executor was shut down before the task was acceptedThreadCreationException - if a thread could not be created for some reasonjava.util.concurrent.RejectedExecutionException - if execution is rejected for some other reasonjava.lang.NullPointerException - if command is nullpublic void shutdown()
shutdown in interface java.util.concurrent.ExecutorServicepublic java.util.List<java.lang.Runnable> shutdownNow()
shutdownNow in interface java.util.concurrent.ExecutorServicepublic boolean isShutdown()
isShutdown in interface java.util.concurrent.ExecutorServicepublic boolean isTerminated()
isTerminated in interface java.util.concurrent.ExecutorServicepublic boolean awaitTermination(long timeout,
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException
awaitTermination in interface java.util.concurrent.ExecutorServicejava.lang.InterruptedExceptionpublic boolean isAllowCoreThreadTimeout()
isAllowCoreThreadTimeout in interface BoundedQueueThreadPoolExecutorMBeanpublic void setAllowCoreThreadTimeout(boolean allowCoreThreadTimeout)
setAllowCoreThreadTimeout in interface BoundedQueueThreadPoolExecutorMBeanpublic int getCoreThreads()
getCoreThreads in interface BoundedQueueThreadPoolExecutorMBeanpublic void setCoreThreads(int coreThreads)
setCoreThreads in interface BoundedQueueThreadPoolExecutorMBeanpublic int getMaxThreads()
getMaxThreads in interface ThreadPoolExecutorMBeanpublic void setMaxThreads(int maxThreads)
setMaxThreads in interface ThreadPoolExecutorMBeanpublic long getKeepAliveTime()
getKeepAliveTime in interface ThreadPoolExecutorMBeanpublic void setKeepAliveTime(long keepAliveTime,
java.util.concurrent.TimeUnit keepAliveTimeUnit)
keepAliveTime - the amount of timekeepAliveTimeUnit - the unit of timepublic void setKeepAliveTime(long milliseconds)
setKeepAliveTime in interface ThreadPoolExecutorMBeanpublic boolean isBlocking()
isBlocking in interface BoundedThreadPoolExecutorMBeantrue if blocking is enabled, false if the handoff executor is usedpublic void setBlocking(boolean blocking)
setBlocking in interface BoundedThreadPoolExecutorMBeanblocking - true if blocking is enabled, false if the handoff executor is usedpublic java.util.concurrent.Executor getHandoffExecutor()
public void setHandoffExecutor(java.util.concurrent.Executor handoffExecutor)
handoffExecutor - the handoff executorpublic <A> void addShutdownListener(EventListener<A> shutdownListener, A attachment)
addShutdownListener in interface ShutdownListenableA - the attachment typeshutdownListener - the listenerattachment - the attachment value to pass to the listenerprivate void startNewThread(java.lang.Runnable task)
private java.lang.Runnable pollTask()
private java.lang.Runnable takeTask()
public int getCurrentThreadCount()
getCurrentThreadCount in interface ThreadExecutorMBeanpublic int getLargestThreadCount()
getLargestThreadCount in interface ThreadExecutorMBeanpublic int getRejectedCount()
getRejectedCount in interface ThreadExecutorMBeanpublic int getQueueSize()
getQueueSize in interface ThreadExecutorMBeanprivate void runTask(java.lang.Runnable task)