org.jboss.threads
Class JBossExecutors

java.lang.Object
  extended by org.jboss.threads.JBossExecutors

public final class JBossExecutors
extends java.lang.Object


Method Summary
static java.util.concurrent.RejectedExecutionHandler abortPolicy()
          Get the abort policy for a ThreadPoolExecutor.
static java.util.concurrent.RejectedExecutionHandler callerRunsPolicy()
          Get the caller-runs policy for a ThreadPoolExecutor.
static DirectExecutor contextClassLoaderExecutor(DirectExecutor delegate, java.lang.ClassLoader taskClassLoader)
          Create a direct executor which runs tasks with the given context class loader.
static DirectExecutor directExecutor()
          Get the direct executor.
static DirectExecutorService directExecutorService()
          Get the direct executor service.
static DirectExecutor discardingExecutor()
          Get the discarding executor.
static DirectExecutorService discardingExecutorService()
          Get the discarding executor service.
static java.util.concurrent.RejectedExecutionHandler discardOldestPolicy()
          Get the discard-oldest policy for a ThreadPoolExecutor.
static java.util.concurrent.RejectedExecutionHandler discardPolicy()
          Get the discard policy for a ThreadPoolExecutor.
static DirectExecutor exceptionLoggingExecutor(DirectExecutor delegate, java.lang.Object log)
          Create a direct executor which consumes and logs errors that are thrown.
static java.lang.Runnable executorTask(DirectExecutor executor, java.lang.Runnable task)
          Get a task that runs the given task through the given direct executor.
static java.util.concurrent.RejectedExecutionHandler handoffPolicy(java.util.concurrent.Executor target)
          Get a handoff policy for a ThreadPoolExecutor.
static DirectExecutor privilegedExecutor(DirectExecutor delegate, java.security.AccessControlContext context)
          Create a direct executor which runs with the privileges given by the supplied AccessControlContext instance.
static DirectExecutorService protectedDirectExecutorService(DirectExecutor target)
          Wrap a direct executor with an DirectExecutorService instance which supports all the features of ExecutorService except for shutting down the executor.
static java.util.concurrent.ExecutorService protectedExecutorService(java.util.concurrent.Executor target)
          Wrap an executor with an ExecutorService instance which supports all the features of ExecutorService except for shutting down the executor.
static java.util.concurrent.ScheduledExecutorService protectedScheduledExecutorService(java.util.concurrent.ScheduledExecutorService target)
          Wrap a scheduled executor with a ScheduledExecutorService instance which supports all the features of ScheduledExecutorService except for shutting down the executor.
static DirectExecutor rejectingExecutor()
          Get the rejecting executor.
static DirectExecutorService rejectingExecutorService()
          Get the rejecting executor service.
static java.util.concurrent.Executor threadFactoryExecutor(java.util.concurrent.ThreadFactory factory)
          Create an executor that executes each task in a new thread.
static DirectExecutor threadNameExecutor(DirectExecutor delegate, java.lang.String newName)
          Create a direct executor which changes the thread name for the duration of a task.
static DirectExecutor threadNameNotateExecutor(DirectExecutor delegate, java.lang.String notation)
          Create a direct executor which adds a note to the thread name for the duration of a task.
static java.util.concurrent.Executor wrappingExecutor(java.util.concurrent.Executor delegate, DirectExecutor taskWrapper)
          An executor which delegates to another executor, wrapping each task in a task wrapper.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

directExecutor

public static DirectExecutor directExecutor()
Get the direct executor. This executor will immediately run any task it is given, and propagate back any run-time exceptions thrown.

Returns:
the direct executor instance

directExecutorService

public static DirectExecutorService directExecutorService()
Get the direct executor service. This executor will immediately run any task it is given, and propagate back any run-time exceptions thrown. It cannot be shut down.

Returns:
the direct executor service instance

rejectingExecutor

public static DirectExecutor rejectingExecutor()
Get the rejecting executor. This executor will reject any task submitted to it.

Returns:
the rejecting executor instance

rejectingExecutorService

public static DirectExecutorService rejectingExecutorService()
Get the rejecting executor service. This executor will reject any task submitted to it. It cannot be shut down.

Returns:
the rejecting executor service instance

discardingExecutor

public static DirectExecutor discardingExecutor()
Get the discarding executor. This executor will silently discard any task submitted to it.

Returns:
the discarding executor instance

discardingExecutorService

public static DirectExecutorService discardingExecutorService()
Get the discarding executor service. This executor will silently discard any task submitted to it. It cannot be shut down.

Returns:
the discarding executor service instance

executorTask

public static java.lang.Runnable executorTask(DirectExecutor executor,
                                              java.lang.Runnable task)
Get a task that runs the given task through the given direct executor.

Parameters:
executor - the executor to run the task through
task - the task to run
Returns:
an encapsulating task

wrappingExecutor

public static java.util.concurrent.Executor wrappingExecutor(java.util.concurrent.Executor delegate,
                                                             DirectExecutor taskWrapper)
An executor which delegates to another executor, wrapping each task in a task wrapper.

Parameters:
delegate - the delegate executor
taskWrapper - the task wrapper
Returns:
a wrapping executor

privilegedExecutor

public static DirectExecutor privilegedExecutor(DirectExecutor delegate,
                                                java.security.AccessControlContext context)
Create a direct executor which runs with the privileges given by the supplied AccessControlContext instance.

Parameters:
delegate - the executor to delegate to at the privileged level
context - the AccessControlContext to use
Returns:
the new direct executor

contextClassLoaderExecutor

public static DirectExecutor contextClassLoaderExecutor(DirectExecutor delegate,
                                                        java.lang.ClassLoader taskClassLoader)
Create a direct executor which runs tasks with the given context class loader.

Parameters:
delegate - the executor to delegate to
taskClassLoader - the context class loader to use
Returns:
the new direct executor

threadNameExecutor

public static DirectExecutor threadNameExecutor(DirectExecutor delegate,
                                                java.lang.String newName)
Create a direct executor which changes the thread name for the duration of a task.

Parameters:
delegate - the executor to delegate to
newName - the thread name to use
Returns:
the new direct executor

threadNameNotateExecutor

public static DirectExecutor threadNameNotateExecutor(DirectExecutor delegate,
                                                      java.lang.String notation)
Create a direct executor which adds a note to the thread name for the duration of a task.

Parameters:
delegate - the executor to delegate to
notation - the note to use
Returns:
the new direct executor

exceptionLoggingExecutor

public static DirectExecutor exceptionLoggingExecutor(DirectExecutor delegate,
                                                      java.lang.Object log)
Create a direct executor which consumes and logs errors that are thrown.

Parameters:
delegate - the executor to delegate to
log - the logger to which exceptions are written at the error level
Returns:
the new direct executor

threadFactoryExecutor

public static java.util.concurrent.Executor threadFactoryExecutor(java.util.concurrent.ThreadFactory factory)
Create an executor that executes each task in a new thread.

Parameters:
factory - the thread factory to use
Returns:
the executor

abortPolicy

public static java.util.concurrent.RejectedExecutionHandler abortPolicy()
Get the abort policy for a ThreadPoolExecutor.

Returns:
the abort policy
See Also:
ThreadPoolExecutor.AbortPolicy

callerRunsPolicy

public static java.util.concurrent.RejectedExecutionHandler callerRunsPolicy()
Get the caller-runs policy for a ThreadPoolExecutor.

Returns:
the caller-runs policy
See Also:
ThreadPoolExecutor.CallerRunsPolicy

discardOldestPolicy

public static java.util.concurrent.RejectedExecutionHandler discardOldestPolicy()
Get the discard-oldest policy for a ThreadPoolExecutor.

Returns:
the discard-oldest policy
See Also:
ThreadPoolExecutor.DiscardOldestPolicy

discardPolicy

public static java.util.concurrent.RejectedExecutionHandler discardPolicy()
Get the discard policy for a ThreadPoolExecutor.

Returns:
the discard policy
See Also:
ThreadPoolExecutor.DiscardPolicy

handoffPolicy

public static java.util.concurrent.RejectedExecutionHandler handoffPolicy(java.util.concurrent.Executor target)
Get a handoff policy for a ThreadPoolExecutor. The returned instance will delegate to another executor in the event that the task is rejected.

Parameters:
target - the target executor
Returns:
the new handoff policy implementation

protectedExecutorService

public static java.util.concurrent.ExecutorService protectedExecutorService(java.util.concurrent.Executor target)
Wrap an executor with an ExecutorService instance which supports all the features of ExecutorService except for shutting down the executor.

Parameters:
target - the target executor
Returns:
the executor service

protectedDirectExecutorService

public static DirectExecutorService protectedDirectExecutorService(DirectExecutor target)
Wrap a direct executor with an DirectExecutorService instance which supports all the features of ExecutorService except for shutting down the executor.

Parameters:
target - the target executor
Returns:
the executor service

protectedScheduledExecutorService

public static java.util.concurrent.ScheduledExecutorService protectedScheduledExecutorService(java.util.concurrent.ScheduledExecutorService target)
Wrap a scheduled executor with a ScheduledExecutorService instance which supports all the features of ScheduledExecutorService except for shutting down the executor.

Parameters:
target - the target executor
Returns:
the executor service


Copyright © 2011. All Rights Reserved.