JBoss Threads 2.0.0.GA-redhat-2

org.jboss.threads
Class QueueExecutor

java.lang.Object
  extended by java.util.concurrent.AbstractExecutorService
      extended by org.jboss.threads.QueueExecutor
All Implemented Interfaces:
Executor, ExecutorService, BlockingExecutor, BlockingExecutorService, BoundedQueueThreadPoolExecutorMBean, BoundedThreadPoolExecutorMBean, ThreadExecutorMBean, ThreadPoolExecutorMBean, ShutdownListenable

public final class QueueExecutor
extends AbstractExecutorService
implements BlockingExecutorService, BoundedQueueThreadPoolExecutorMBean, ShutdownListenable

An executor which uses a regular queue to hold tasks. The executor may be tuned at runtime in many ways.


Constructor Summary
QueueExecutor(int coreThreads, int maxThreads, long keepAliveTime, TimeUnit keepAliveTimeUnit, int queueLength, ThreadFactory threadFactory, boolean blocking, Executor handoffExecutor)
          Create a new instance.
QueueExecutor(int coreThreads, int maxThreads, long keepAliveTime, TimeUnit keepAliveTimeUnit, Queue<Runnable> queue, ThreadFactory threadFactory, boolean blocking, Executor handoffExecutor)
          Create a new instance.
QueueExecutor(int coreThreads, int maxThreads, long keepAliveTime, TimeUnit keepAliveTimeUnit, Queue<Runnable> queue, ThreadFactory threadFactory, boolean blocking, Executor handoffExecutor, DirectExecutor taskExecutor)
          Create a new instance.
 
Method Summary
<A> void
addShutdownListener(EventListener<A> shutdownListener, A attachment)
          Add a shutdown listener.
 boolean awaitTermination(long timeout, TimeUnit unit)
          
 void execute(Runnable task)
          Execute a task.
 void executeBlocking(Runnable task)
          Execute a task, blocking until it can be accepted, or until the calling thread is interrupted.
 void executeBlocking(Runnable task, long timeout, TimeUnit unit)
          Execute a task, blocking until it can be accepted, a timeout elapses, or the calling thread is interrupted.
 void executeNonBlocking(Runnable task)
          Execute a task, without blocking.
 int getCoreThreads()
          
 int getCurrentThreadCount()
          
 Executor getHandoffExecutor()
          Get the handoff executor which is called when a task cannot be accepted immediately.
 long getKeepAliveTime()
          
 int getLargestThreadCount()
          
 int getMaxThreads()
          
 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()
          
 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(Executor handoffExecutor)
          Set the handoff executor which is called when a task cannot be accepted immediately.
 void setKeepAliveTime(long milliseconds)
          
 void setKeepAliveTime(long keepAliveTime, TimeUnit keepAliveTimeUnit)
          Set the keep-alive time to the given amount of time.
 void setMaxThreads(int maxThreads)
          
 void shutdown()
          
 List<Runnable> shutdownNow()
          
 
Methods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor, submit, submit, submit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.concurrent.ExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, submit, submit, submit
 

Constructor Detail

QueueExecutor

public QueueExecutor(int coreThreads,
                     int maxThreads,
                     long keepAliveTime,
                     TimeUnit keepAliveTimeUnit,
                     Queue<Runnable> queue,
                     ThreadFactory threadFactory,
                     boolean blocking,
                     Executor handoffExecutor,
                     DirectExecutor taskExecutor)
Create a new instance.

Parameters:
coreThreads - the number of threads to create before enqueueing tasks
maxThreads - the maximum number of threads to create
keepAliveTime - the amount of time that an idle thread should remain active
keepAliveTimeUnit - the unit of time for keepAliveTime
queue - the queue to use for tasks
threadFactory - the thread factory to use for new threads
blocking - true if the executor should block when the queue is full and no threads are available, false to use the handoff executor
handoffExecutor - the executor which is called when blocking is disabled and a task cannot be accepted, or null to reject the task
taskExecutor - the executor to use to execute tasks

QueueExecutor

public QueueExecutor(int coreThreads,
                     int maxThreads,
                     long keepAliveTime,
                     TimeUnit keepAliveTimeUnit,
                     Queue<Runnable> queue,
                     ThreadFactory threadFactory,
                     boolean blocking,
                     Executor handoffExecutor)
Create a new instance.

Parameters:
coreThreads - the number of threads to create before enqueueing tasks
maxThreads - the maximum number of threads to create
keepAliveTime - the amount of time that an idle thread should remain active
keepAliveTimeUnit - the unit of time for keepAliveTime
queue - the queue to use for tasks
threadFactory - the thread factory to use for new threads
blocking - true if the executor should block when the queue is full and no threads are available, false to use the handoff executor
handoffExecutor - the executor which is called when blocking is disabled and a task cannot be accepted, or null to reject the task

QueueExecutor

public QueueExecutor(int coreThreads,
                     int maxThreads,
                     long keepAliveTime,
                     TimeUnit keepAliveTimeUnit,
                     int queueLength,
                     ThreadFactory threadFactory,
                     boolean blocking,
                     Executor handoffExecutor)
Create a new instance.

Parameters:
coreThreads - the number of threads to create before enqueueing tasks
maxThreads - the maximum number of threads to create
keepAliveTime - the amount of time that an idle thread should remain active
keepAliveTimeUnit - the unit of time for keepAliveTime
queueLength - the fixed queue length to use for tasks
threadFactory - the thread factory to use for new threads
blocking - true if the executor should block when the queue is full and no threads are available, false to use the handoff executor
handoffExecutor - the executor which is called when blocking is disabled and a task cannot be accepted, or null to reject the task
Method Detail

execute

public void execute(Runnable task)
             throws RejectedExecutionException
Execute a task.

Specified by:
execute in interface Executor
Specified by:
execute in interface BlockingExecutor
Parameters:
task - the task to execute
Throws:
RejectedExecutionException - when a task is rejected by the handoff executor
StoppedExecutorException - when the executor is terminating
ExecutionInterruptedException - when blocking is enabled and the current thread is interrupted before a task could be accepted

executeBlocking

public void executeBlocking(Runnable task)
                     throws RejectedExecutionException,
                            InterruptedException
Execute a task, blocking until it can be accepted, or until the calling thread is interrupted.

Specified by:
executeBlocking in interface BlockingExecutor
Parameters:
task - the task to submit
Throws:
StoppedExecutorException - if the executor was shut down before the task was accepted
ThreadCreationException - if a thread could not be created for some reason
RejectedExecutionException - if execution is rejected for some other reason
InterruptedException - if the current thread was interrupted before the task could be accepted
NullPointerException - if command is null

executeBlocking

public void executeBlocking(Runnable task,
                            long timeout,
                            TimeUnit unit)
                     throws RejectedExecutionException,
                            InterruptedException
Execute a task, blocking until it can be accepted, a timeout elapses, or the calling thread is interrupted.

Specified by:
executeBlocking in interface BlockingExecutor
Parameters:
task - the task to submit
timeout - the amount of time to wait
unit - the unit of time
Throws:
ExecutionTimedOutException - if the timeout elapsed before a task could be accepted
StoppedExecutorException - if the executor was shut down before the task was accepted
ThreadCreationException - if a thread could not be created for some reason
RejectedExecutionException - if execution is rejected for some other reason
InterruptedException - if the current thread was interrupted before the task could be accepted
NullPointerException - if command is null

executeNonBlocking

public void executeNonBlocking(Runnable task)
                        throws RejectedExecutionException
Execute a task, without blocking.

Specified by:
executeNonBlocking in interface BlockingExecutor
Parameters:
task - the task to submit
Throws:
StoppedExecutorException - if the executor was shut down before the task was accepted
ThreadCreationException - if a thread could not be created for some reason
RejectedExecutionException - if execution is rejected for some other reason
NullPointerException - if command is null

shutdown

public void shutdown()

Specified by:
shutdown in interface ExecutorService

shutdownNow

public List<Runnable> shutdownNow()

Specified by:
shutdownNow in interface ExecutorService

isShutdown

public boolean isShutdown()

Specified by:
isShutdown in interface ExecutorService

isTerminated

public boolean isTerminated()

Specified by:
isTerminated in interface ExecutorService

awaitTermination

public boolean awaitTermination(long timeout,
                                TimeUnit unit)
                         throws InterruptedException

Specified by:
awaitTermination in interface ExecutorService
Throws:
InterruptedException

isAllowCoreThreadTimeout

public boolean isAllowCoreThreadTimeout()

Specified by:
isAllowCoreThreadTimeout in interface BoundedQueueThreadPoolExecutorMBean

setAllowCoreThreadTimeout

public void setAllowCoreThreadTimeout(boolean allowCoreThreadTimeout)

Specified by:
setAllowCoreThreadTimeout in interface BoundedQueueThreadPoolExecutorMBean

getCoreThreads

public int getCoreThreads()

Specified by:
getCoreThreads in interface BoundedQueueThreadPoolExecutorMBean

setCoreThreads

public void setCoreThreads(int coreThreads)

Specified by:
setCoreThreads in interface BoundedQueueThreadPoolExecutorMBean

getMaxThreads

public int getMaxThreads()

Specified by:
getMaxThreads in interface ThreadPoolExecutorMBean

setMaxThreads

public void setMaxThreads(int maxThreads)

Specified by:
setMaxThreads in interface ThreadPoolExecutorMBean

getKeepAliveTime

public long getKeepAliveTime()

Specified by:
getKeepAliveTime in interface ThreadPoolExecutorMBean

setKeepAliveTime

public void setKeepAliveTime(long keepAliveTime,
                             TimeUnit keepAliveTimeUnit)
Set the keep-alive time to the given amount of time.

Parameters:
keepAliveTime - the amount of time
keepAliveTimeUnit - the unit of time

setKeepAliveTime

public void setKeepAliveTime(long milliseconds)

Specified by:
setKeepAliveTime in interface ThreadPoolExecutorMBean

isBlocking

public boolean isBlocking()
Determine whether this thread pool executor is set to block when a task cannot be accepted immediately.

Specified by:
isBlocking in interface BoundedThreadPoolExecutorMBean
Returns:
true if blocking is enabled, false if the handoff executor is used

setBlocking

public void setBlocking(boolean blocking)
Set whether this thread pool executor should be set to block when a task cannot be accepted immediately.

Specified by:
setBlocking in interface BoundedThreadPoolExecutorMBean
Parameters:
blocking - true if blocking is enabled, false if the handoff executor is used

getHandoffExecutor

public Executor getHandoffExecutor()
Get the handoff executor which is called when a task cannot be accepted immediately.

Returns:
the handoff executor

setHandoffExecutor

public void setHandoffExecutor(Executor handoffExecutor)
Set the handoff executor which is called when a task cannot be accepted immediately.

Parameters:
handoffExecutor - the handoff executor

addShutdownListener

public <A> void addShutdownListener(EventListener<A> shutdownListener,
                                    A attachment)
Add a shutdown listener. If the target object is already shut down, the listener is invoked directly.

Specified by:
addShutdownListener in interface ShutdownListenable
Type Parameters:
A - the attachment type
Parameters:
shutdownListener - the listener
attachment - the attachment value to pass to the listener

getCurrentThreadCount

public int getCurrentThreadCount()

Specified by:
getCurrentThreadCount in interface ThreadExecutorMBean

getLargestThreadCount

public int getLargestThreadCount()

Specified by:
getLargestThreadCount in interface ThreadExecutorMBean

getRejectedCount

public int getRejectedCount()

Specified by:
getRejectedCount in interface ThreadExecutorMBean

JBoss Threads 2.0.0.GA-redhat-2

Copyright © 2012 JBoss by Red Hat. All Rights Reserved.