Package org.jboss.threads
Class JBossExecutors
- java.lang.Object
-
- org.jboss.threads.JBossExecutors
-
public final class JBossExecutors extends Object
JBoss thread- and executor-related utility and factory methods.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static RejectedExecutionHandlerabortPolicy()Get the abort policy for aThreadPoolExecutor.static RejectedExecutionHandlercallerRunsPolicy()Get the caller-runs policy for aThreadPoolExecutor.static RunnableclassLoaderPreservingTask(Runnable delegate)Create a task that delegates to the given task, preserving the context classloader which was in effect when this method was invoked.static ExecutorcontextClassLoaderExecutor(Executor delegate, ClassLoader taskClassLoader)Create an executor which runs tasks with the given context class loader.static RunnablecontextClassLoaderResetter()Get aRunnablewhich, when executed, clears the thread context class loader (if the caller has sufficient privileges).static ExecutordirectExecutor()Get the direct executor.static ExecutordiscardingExecutor()Get the discarding executor.static ExecutorServicediscardingExecutorService()Get the discarding executor service.static RejectedExecutionHandlerdiscardOldestPolicy()Get the discard-oldest policy for aThreadPoolExecutor.static RejectedExecutionHandlerdiscardPolicy()Get the discard policy for aThreadPoolExecutor.static RejectedExecutionHandlerhandoffPolicy(Executor target)Get a handoff policy for aThreadPoolExecutor.static Thread.UncaughtExceptionHandlerloggingExceptionHandler()Get an uncaught exception handler which logs to the default error logger.static Thread.UncaughtExceptionHandlerloggingExceptionHandler(String categoryName)Get an uncaught exception handler which logs to the given logger.static Thread.UncaughtExceptionHandlerloggingExceptionHandler(org.jboss.logging.Logger log)Get an uncaught exception handler which logs to the given logger.static RunnablenullRunnable()Get the null runnable which does nothing.static ExecutorServiceprotectedExecutorService(Executor target)Wrap an executor with anExecutorServiceinstance which supports all the features ofExecutorServiceexcept for shutting down the executor.static ScheduledExecutorServiceprotectedScheduledExecutorService(ScheduledExecutorService target)Wrap a scheduled executor with aScheduledExecutorServiceinstance which supports all the features ofScheduledExecutorServiceexcept for shutting down the executor.static ExecutorrejectingExecutor()Get the rejecting executor.static ExecutorrejectingExecutor(String message)Get a rejecting executor.static ExecutorServicerejectingExecutorService()Get the rejecting executor service.static ExecutorServicerejectingExecutorService(String message)Get the rejecting executor service.static ThreadFactoryresettingThreadFactory(ThreadFactory delegate)Create a thread factory which resets all thread-local storage and delegates to the given thread factory.
-
-
-
Method Detail
-
directExecutor
public static Executor 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
-
rejectingExecutor
public static Executor rejectingExecutor()
Get the rejecting executor. This executor will reject any task submitted to it.- Returns:
- the rejecting executor instance
-
rejectingExecutor
public static Executor rejectingExecutor(String message)
Get a rejecting executor. This executor will reject any task submitted to it with the given message.- Parameters:
message- the reject message- Returns:
- the rejecting executor instance
-
rejectingExecutorService
public static ExecutorService 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
-
rejectingExecutorService
public static ExecutorService rejectingExecutorService(String message)
Get the rejecting executor service. This executor will reject any task submitted to it with the given message. It cannot be shut down.- Parameters:
message- the reject message- Returns:
- the rejecting executor service instance
-
discardingExecutor
public static Executor discardingExecutor()
Get the discarding executor. This executor will silently discard any task submitted to it.- Returns:
- the discarding executor instance
-
discardingExecutorService
public static ExecutorService 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
-
contextClassLoaderExecutor
public static Executor contextClassLoaderExecutor(Executor delegate, ClassLoader taskClassLoader)
Create an executor which runs tasks with the given context class loader.- Parameters:
delegate- the executor to delegate totaskClassLoader- the context class loader to use- Returns:
- the new direct executor
-
abortPolicy
public static RejectedExecutionHandler abortPolicy()
Get the abort policy for aThreadPoolExecutor.- Returns:
- the abort policy
- See Also:
ThreadPoolExecutor.AbortPolicy
-
callerRunsPolicy
public static RejectedExecutionHandler callerRunsPolicy()
Get the caller-runs policy for aThreadPoolExecutor.- Returns:
- the caller-runs policy
- See Also:
ThreadPoolExecutor.CallerRunsPolicy
-
discardOldestPolicy
public static RejectedExecutionHandler discardOldestPolicy()
Get the discard-oldest policy for aThreadPoolExecutor.- Returns:
- the discard-oldest policy
- See Also:
ThreadPoolExecutor.DiscardOldestPolicy
-
discardPolicy
public static RejectedExecutionHandler discardPolicy()
Get the discard policy for aThreadPoolExecutor.- Returns:
- the discard policy
- See Also:
ThreadPoolExecutor.DiscardPolicy
-
handoffPolicy
public static RejectedExecutionHandler handoffPolicy(Executor target)
Get a handoff policy for aThreadPoolExecutor. 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 ExecutorService protectedExecutorService(Executor target)
Wrap an executor with anExecutorServiceinstance which supports all the features ofExecutorServiceexcept for shutting down the executor.- Parameters:
target- the target executor- Returns:
- the executor service
-
protectedScheduledExecutorService
public static ScheduledExecutorService protectedScheduledExecutorService(ScheduledExecutorService target)
Wrap a scheduled executor with aScheduledExecutorServiceinstance which supports all the features ofScheduledExecutorServiceexcept for shutting down the executor.- Parameters:
target- the target executor- Returns:
- the executor service
-
resettingThreadFactory
public static ThreadFactory resettingThreadFactory(ThreadFactory delegate) throws SecurityException
Create a thread factory which resets all thread-local storage and delegates to the given thread factory. You must have theRuntimePermission("modifyThread")permission to use this method.- Parameters:
delegate- the delegate thread factory- Returns:
- the resetting thread factory
- Throws:
SecurityException- if the caller does not have theRuntimePermission("modifyThread")permission
-
nullRunnable
public static Runnable nullRunnable()
Get the null runnable which does nothing.- Returns:
- the null runnable
-
contextClassLoaderResetter
public static Runnable contextClassLoaderResetter()
Get aRunnablewhich, when executed, clears the thread context class loader (if the caller has sufficient privileges).- Returns:
- the runnable
-
classLoaderPreservingTask
public static Runnable classLoaderPreservingTask(Runnable delegate) throws SecurityException
Create a task that delegates to the given task, preserving the context classloader which was in effect when this method was invoked.- Parameters:
delegate- the delegate runnable- Returns:
- the wrapping runnable
- Throws:
SecurityException- if a security manager exists and the caller does not have the"copyClassLoader"RuntimePermission.
-
loggingExceptionHandler
public static Thread.UncaughtExceptionHandler loggingExceptionHandler(org.jboss.logging.Logger log)
Get an uncaught exception handler which logs to the given logger.- Parameters:
log- the logger- Returns:
- the handler
-
loggingExceptionHandler
public static Thread.UncaughtExceptionHandler loggingExceptionHandler(String categoryName)
Get an uncaught exception handler which logs to the given logger.- Parameters:
categoryName- the name of the logger category to log to- Returns:
- the handler
-
loggingExceptionHandler
public static Thread.UncaughtExceptionHandler loggingExceptionHandler()
Get an uncaught exception handler which logs to the default error logger.- Returns:
- the handler
-
-