JBoss Threads 2.0.0.GA

org.jboss.threads
Class OrderedExecutor

java.lang.Object
  extended by java.util.concurrent.AbstractExecutorService
      extended by org.jboss.threads.OrderedExecutor
All Implemented Interfaces:
Executor, ExecutorService, BlockingExecutor, BlockingExecutorService

public final class OrderedExecutor
extends AbstractExecutorService
implements BlockingExecutorService

An executor that always runs all tasks in queue order, using a delegate executor to run the tasks.

More specifically, if a FIFO queue type is used, any call B to the execute(Runnable) method that happens-after another call A to the same method, will result in B's task running after A's.


Constructor Summary
OrderedExecutor(Executor parent)
          Construct a new instance using an unbounded FIFO queue.
OrderedExecutor(Executor parent, int queueLength)
          Construct a new instance using a bounded FIFO queue of the given size and a blocking reject policy.
OrderedExecutor(Executor parent, int queueLength, boolean blocking, Executor handoffExecutor)
          Construct a new instance using a bounded FIFO queue of the given size and a handoff reject policy.
OrderedExecutor(Executor parent, int queueLength, Executor handoffExecutor)
          Construct a new instance using a bounded FIFO queue of the given size and a handoff reject policy.
OrderedExecutor(Executor parent, Queue<Runnable> queue)
          Construct a new instance using the given queue and a blocking reject policy.
OrderedExecutor(Executor parent, Queue<Runnable> queue, boolean blocking, Executor handoffExecutor)
          Construct a new instance.
 
Method Summary
 boolean awaitTermination(long timeout, TimeUnit unit)
           
 void execute(Runnable task)
          Run 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.
 boolean isShutdown()
           
 boolean isTerminated()
           
 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

OrderedExecutor

public OrderedExecutor(Executor parent)
Construct a new instance using an unbounded FIFO queue. Since the queue is unbounded, tasks are never rejected.

Parameters:
parent - the parent to delegate tasks to

OrderedExecutor

public OrderedExecutor(Executor parent,
                       Queue<Runnable> queue)
Construct a new instance using the given queue and a blocking reject policy.

Parameters:
parent - the parent to delegate tasks to
queue - the queue to use to hold tasks

OrderedExecutor

public OrderedExecutor(Executor parent,
                       int queueLength)
Construct a new instance using a bounded FIFO queue of the given size and a blocking reject policy.

Parameters:
parent - the parent to delegate tasks to
queueLength - the fixed length of the queue to use to hold tasks

OrderedExecutor

public OrderedExecutor(Executor parent,
                       int queueLength,
                       Executor handoffExecutor)
Construct a new instance using a bounded FIFO queue of the given size and a handoff reject policy.

Parameters:
parent - the parent executor
queueLength - the fixed length of the queue to use to hold tasks
handoffExecutor - the executor to hand tasks to if the queue is full

OrderedExecutor

public OrderedExecutor(Executor parent,
                       Queue<Runnable> queue,
                       boolean blocking,
                       Executor handoffExecutor)
Construct a new instance.

Parameters:
parent - the parent executor
queue - the task queue to use
blocking - true if rejected tasks should block, false if rejected tasks should be handed off
handoffExecutor - the executor to hand tasks to if the queue is full

OrderedExecutor

public OrderedExecutor(Executor parent,
                       int queueLength,
                       boolean blocking,
                       Executor handoffExecutor)
Construct a new instance using a bounded FIFO queue of the given size and a handoff reject policy.

Parameters:
parent - the parent executor
queueLength - the fixed length of the queue to use to hold tasks
blocking - true if rejected tasks should block, false if rejected tasks should be handed off
handoffExecutor - the executor to hand tasks to if the queue is full
Method Detail

execute

public void execute(Runnable task)
Run a task.

Specified by:
execute in interface Executor
Specified by:
execute in interface BlockingExecutor
Parameters:
task - the task to run.

executeBlocking

public void executeBlocking(Runnable task)
                     throws RejectedExecutionException,
                            InterruptedException
Description copied from interface: BlockingExecutor
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

executeBlocking

public void executeBlocking(Runnable task,
                            long timeout,
                            TimeUnit unit)
                     throws RejectedExecutionException,
                            InterruptedException
Description copied from interface: BlockingExecutor
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

executeNonBlocking

public void executeNonBlocking(Runnable task)
                        throws RejectedExecutionException
Description copied from interface: BlockingExecutor
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

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

shutdown

public void shutdown()
Specified by:
shutdown in interface ExecutorService

shutdownNow

public List<Runnable> shutdownNow()
Specified by:
shutdownNow in interface ExecutorService

JBoss Threads 2.0.0.GA

Copyright © 2012 JBoss, a division of Red Hat, Inc.. All Rights Reserved.