Class JBossExecutors
java.lang.Object
org.jboss.threads.JBossExecutors
JBoss thread- and executor-related utility and factory methods.
-
Method Summary
Modifier and TypeMethodDescriptionstatic RejectedExecutionHandlerGet the abort policy for aThreadPoolExecutor.static RejectedExecutionHandlerGet 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 RunnableGet aRunnablewhich, when executed, clears the thread context class loader (if the caller has sufficient privileges).static ExecutorGet the direct executor.static ExecutorGet the discarding executor.static ExecutorServiceGet the discarding executor service.static RejectedExecutionHandlerGet the discard-oldest policy for aThreadPoolExecutor.static RejectedExecutionHandlerGet the discard policy for aThreadPoolExecutor.static RejectedExecutionHandlerhandoffPolicy(Executor target) Get a handoff policy for aThreadPoolExecutor.Get an uncaught exception handler which logs to the default error logger.loggingExceptionHandler(String categoryName) Get an uncaught exception handler which logs to the given logger.loggingExceptionHandler(org.jboss.logging.Logger log) Get an uncaught exception handler which logs to the given logger.static RunnableGet 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 ScheduledExecutorServiceWrap a scheduled executor with aScheduledExecutorServiceinstance which supports all the features ofScheduledExecutorServiceexcept for shutting down the executor.static ExecutorGet the rejecting executor.static ExecutorrejectingExecutor(String message) Get a rejecting executor.static ExecutorServiceGet 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 Details
-
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
Get the rejecting executor. This executor will reject any task submitted to it.- Returns:
- the rejecting executor instance
-
rejectingExecutor
-
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
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
Get the discarding executor. This executor will silently discard any task submitted to it.- Returns:
- the discarding executor instance
-
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
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
Get the abort policy for aThreadPoolExecutor.- Returns:
- the abort policy
- See Also:
-
callerRunsPolicy
Get the caller-runs policy for aThreadPoolExecutor.- Returns:
- the caller-runs policy
- See Also:
-
discardOldestPolicy
Get the discard-oldest policy for aThreadPoolExecutor.- Returns:
- the discard-oldest policy
- See Also:
-
discardPolicy
Get the discard policy for aThreadPoolExecutor.- Returns:
- the discard policy
- See Also:
-
handoffPolicy
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
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
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
Get the null runnable which does nothing.- Returns:
- the null runnable
-
contextClassLoaderResetter
Get aRunnablewhich, when executed, clears the thread context class loader (if the caller has sufficient privileges).- Returns:
- the runnable
-
classLoaderPreservingTask
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
Get an uncaught exception handler which logs to the given logger.- Parameters:
log- the logger- Returns:
- the handler
-
loggingExceptionHandler
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
Get an uncaught exception handler which logs to the default error logger.- Returns:
- the handler
-