Top Description Fields Constructors Methods
org.jboss.threads

public final Class JBossExecutors

extends Object
Class Inheritance
Annotations
@SuppressWarnings:deprecation
Imports
java.lang.reflect.Field, java.util.concurrent.Executor, .ExecutorService, .ThreadPoolExecutor, .RejectedExecutionHandler, .ThreadFactory, .ScheduledExecutorService, java.security.PrivilegedAction, .AccessController, org.jboss.logging.Logger, org.wildfly.common.Assert, sun.misc.Unsafe

JBoss thread- and executor-related utility and factory methods.

Field Summary

Modifier and TypeField and Description
private static final RejectedExecutionHandler
private static final RejectedExecutionHandler
pack-priv static final long
private static final RuntimePermission
private static final RejectedExecutionHandler
private static final RejectedExecutionHandler
private static final ExecutorService
private static final Thread.UncaughtExceptionHandler
private static final Runnable
private static final ExecutorService
pack-priv static final ClassLoader
private static final Runnable
private static final Logger
pack-priv static final Unsafe

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static RejectedExecutionHandler

Returns:

the abort policy
abortPolicy
()

Get the abort policy for a java.util.concurrent.ThreadPoolExecutor.

public static RejectedExecutionHandler

Returns:

the caller-runs policy
callerRunsPolicy
()

Get the caller-runs policy for a java.util.concurrent.ThreadPoolExecutor.

public static Runnable

Returns:

the wrapping runnable
classLoaderPreservingTask
(final Runnable
the delegate runnable
delegate
)

Create a task that delegates to the given task, preserving the context classloader which was in effect when this method was invoked.

pack-priv static Runnable
pack-priv static void
clearContextClassLoader(final Thread
the thread to introspect
thread
)

Privileged method to clear the context class loader of the given thread to a safe non-null value.

public static Executor

Returns:

the new direct executor
contextClassLoaderExecutor
(final Executor
the executor to delegate to
delegate
,
final ClassLoader
the context class loader to use
taskClassLoader
)

Create an executor which runs tasks with the given context class loader.

public static Runnable

Returns:

the runnable
contextClassLoaderResetter
()

Get a Runnable which, when executed, clears the thread context class loader (if the caller has sufficient privileges).

public static Executor

Returns:

the direct executor instance
directExecutor
()

Get the direct executor.

public static Executor

Returns:

the discarding executor instance
discardingExecutor
()

Get the discarding executor.

public static ExecutorService

Returns:

the discarding executor service instance
discardingExecutorService
()

Get the discarding executor service.

public static RejectedExecutionHandler

Returns:

the discard-oldest policy
discardOldestPolicy
()

Get the discard-oldest policy for a java.util.concurrent.ThreadPoolExecutor.

public static RejectedExecutionHandler

Returns:

the discard policy
discardPolicy
()

Get the discard policy for a java.util.concurrent.ThreadPoolExecutor.

pack-priv static ClassLoader

Returns:

the old context class loader
getAndSetContextClassLoader
(final Thread
the thread to introspect
thread
,
final ClassLoader
the new context class loader
newClassLoader
)

Privileged method to get and set the context class loader of the given thread.

pack-priv static ClassLoader

Returns:

the context class loader
getContextClassLoader
(final Thread
the thread to introspect
thread
)

Privileged method to get the context class loader of the given thread.

public static RejectedExecutionHandler

Returns:

the new handoff policy implementation
handoffPolicy
(final Executor
the target executor
target
)

Get a handoff policy for a java.util.concurrent.ThreadPoolExecutor.

public static Thread.UncaughtExceptionHandler

Returns:

the handler
loggingExceptionHandler
(final Logger
the logger
log
)

Get an uncaught exception handler which logs to the given logger.

public static Thread.UncaughtExceptionHandler

Returns:

the handler
loggingExceptionHandler
(final String
the name of the logger category to log to
categoryName
)

Get an uncaught exception handler which logs to the given logger.

public static Thread.UncaughtExceptionHandler

Returns:

the handler
loggingExceptionHandler
()

Get an uncaught exception handler which logs to the default error logger.

public static Runnable

Returns:

the null runnable
nullRunnable
()

Get the null runnable which does nothing.

public static ExecutorService

Returns:

the executor service
protectedExecutorService
(final Executor
the target executor
target
)

Wrap an executor with an ExecutorService instance which supports all the features of ExecutorService except for shutting down the executor.

public static ScheduledExecutorService

Returns:

the executor service
protectedScheduledExecutorService
(final ScheduledExecutorService
the target executor
target
)

Wrap a scheduled executor with a ScheduledExecutorService instance which supports all the features of ScheduledExecutorService except for shutting down the executor.

public static Executor

Returns:

the rejecting executor instance
rejectingExecutor
()

Get the rejecting executor.

public static Executor

Returns:

the rejecting executor instance
rejectingExecutor
(final String
the reject message
message
)

Get a rejecting executor.

public static ExecutorService

Returns:

the rejecting executor service instance
rejectingExecutorService
()

Get the rejecting executor service.

public static ExecutorService

Returns:

the rejecting executor service instance
rejectingExecutorService
(final String
the reject message
message
)

Get the rejecting executor service.

public static ThreadFactory

Returns:

the resetting thread factory
resettingThreadFactory
(final ThreadFactory
the delegate thread factory
delegate
)

Create a thread factory which resets all thread-local storage and delegates to the given thread factory.

pack-priv static void
setContextClassLoader(final Thread
the thread to introspect
thread
,
final ClassLoader
the new context class loader
classLoader
)

Privileged method to set the context class loader of the given thread.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ABORT_POLICYback to summary
private static final RejectedExecutionHandler ABORT_POLICY
CALLER_RUNS_POLICYback to summary
private static final RejectedExecutionHandler CALLER_RUNS_POLICY
contextClassLoaderOffsback to summary
pack-priv static final long contextClassLoaderOffs
COPY_CONTEXT_CLASSLOADER_PERMISSIONback to summary
private static final RuntimePermission COPY_CONTEXT_CLASSLOADER_PERMISSION
DISCARD_OLDEST_POLICYback to summary
private static final RejectedExecutionHandler DISCARD_OLDEST_POLICY
DISCARD_POLICYback to summary
private static final RejectedExecutionHandler DISCARD_POLICY
DISCARDING_EXECUTOR_SERVICEback to summary
private static final ExecutorService DISCARDING_EXECUTOR_SERVICE
LOGGING_HANDLERback to summary
private static final Thread.UncaughtExceptionHandler LOGGING_HANDLER
NULL_RUNNABLEback to summary
private static final Runnable NULL_RUNNABLE
REJECTING_EXECUTOR_SERVICEback to summary
private static final ExecutorService REJECTING_EXECUTOR_SERVICE
SAFE_CLback to summary
pack-priv static final ClassLoader SAFE_CL
TCCL_RESETTERback to summary
private static final Runnable TCCL_RESETTER
THREAD_ERROR_LOGGERback to summary
private static final Logger THREAD_ERROR_LOGGER
unsafeback to summary
pack-priv static final Unsafe unsafe

Constructor Detail

JBossExecutorsback to summary
private JBossExecutors()

Method Detail

abortPolicyback to summary
public static RejectedExecutionHandler abortPolicy()

Get the abort policy for a java.util.concurrent.ThreadPoolExecutor.

Returns:RejectedExecutionHandler

the abort policy

See Also
java.util.concurrent.ThreadPoolExecutor.AbortPolicy
callerRunsPolicyback to summary
public static RejectedExecutionHandler callerRunsPolicy()

Get the caller-runs policy for a java.util.concurrent.ThreadPoolExecutor.

Returns:RejectedExecutionHandler

the caller-runs policy

See Also
java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy
classLoaderPreservingTaskback to summary
public static Runnable classLoaderPreservingTask(final 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:Runnable

the delegate runnable

Returns:Runnable

the wrapping runnable

Exceptions
SecurityException:
if a security manager exists and the caller does not have the "copyClassLoader" RuntimePermission.
classLoaderPreservingTaskUncheckedback to summary
pack-priv static Runnable classLoaderPreservingTaskUnchecked(final Runnable delegate)
clearContextClassLoaderback to summary
pack-priv static void clearContextClassLoader(final Thread thread)

Privileged method to clear the context class loader of the given thread to a safe non-null value.

Parameters
thread:Thread

the thread to introspect

contextClassLoaderExecutorback to summary
public static Executor contextClassLoaderExecutor(final Executor delegate, final ClassLoader taskClassLoader)

Create an executor which runs tasks with the given context class loader.

Parameters
delegate:Executor

the executor to delegate to

taskClassLoader:ClassLoader

the context class loader to use

Returns:Executor

the new direct executor

contextClassLoaderResetterback to summary
public static Runnable contextClassLoaderResetter()

Get a Runnable which, when executed, clears the thread context class loader (if the caller has sufficient privileges).

Returns:Runnable

the runnable

directExecutorback to summary
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:Executor

the direct executor instance

discardingExecutorback to summary
public static Executor discardingExecutor()

Get the discarding executor. This executor will silently discard any task submitted to it.

Returns:Executor

the discarding executor instance

discardingExecutorServiceback to summary
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:ExecutorService

the discarding executor service instance

discardOldestPolicyback to summary
public static RejectedExecutionHandler discardOldestPolicy()

Get the discard-oldest policy for a java.util.concurrent.ThreadPoolExecutor.

Returns:RejectedExecutionHandler

the discard-oldest policy

See Also
java.util.concurrent.ThreadPoolExecutor.DiscardOldestPolicy
discardPolicyback to summary
public static RejectedExecutionHandler discardPolicy()

Get the discard policy for a java.util.concurrent.ThreadPoolExecutor.

Returns:RejectedExecutionHandler

the discard policy

See Also
java.util.concurrent.ThreadPoolExecutor.DiscardPolicy
getAndSetContextClassLoaderback to summary
pack-priv static ClassLoader getAndSetContextClassLoader(final Thread thread, final ClassLoader newClassLoader)

Privileged method to get and set the context class loader of the given thread.

Parameters
thread:Thread

the thread to introspect

newClassLoader:ClassLoader

the new context class loader

Returns:ClassLoader

the old context class loader

getContextClassLoaderback to summary
pack-priv static ClassLoader getContextClassLoader(final Thread thread)

Privileged method to get the context class loader of the given thread.

Parameters
thread:Thread

the thread to introspect

Returns:ClassLoader

the context class loader

handoffPolicyback to summary
public static RejectedExecutionHandler handoffPolicy(final Executor target)

Get a handoff policy for a java.util.concurrent.ThreadPoolExecutor. The returned instance will delegate to another executor in the event that the task is rejected.

Parameters
target:Executor

the target executor

Returns:RejectedExecutionHandler

the new handoff policy implementation

loggingExceptionHandlerback to summary
public static Thread.UncaughtExceptionHandler loggingExceptionHandler(final Logger log)

Get an uncaught exception handler which logs to the given logger.

Parameters
log:Logger

the logger

Returns:Thread.UncaughtExceptionHandler

the handler

loggingExceptionHandlerback to summary
public static Thread.UncaughtExceptionHandler loggingExceptionHandler(final String categoryName)

Get an uncaught exception handler which logs to the given logger.

Parameters
categoryName:String

the name of the logger category to log to

Returns:Thread.UncaughtExceptionHandler

the handler

loggingExceptionHandlerback to summary
public static Thread.UncaughtExceptionHandler loggingExceptionHandler()

Get an uncaught exception handler which logs to the default error logger.

Returns:Thread.UncaughtExceptionHandler

the handler

nullRunnableback to summary
public static Runnable nullRunnable()

Get the null runnable which does nothing.

Returns:Runnable

the null runnable

protectedExecutorServiceback to summary
public static ExecutorService protectedExecutorService(final Executor target)

Wrap an executor with an ExecutorService instance which supports all the features of ExecutorService except for shutting down the executor.

Parameters
target:Executor

the target executor

Returns:ExecutorService

the executor service

protectedScheduledExecutorServiceback to summary
public static ScheduledExecutorService protectedScheduledExecutorService(final 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:ScheduledExecutorService

the target executor

Returns:ScheduledExecutorService

the executor service

rejectingExecutorback to summary
public static Executor rejectingExecutor()

Get the rejecting executor. This executor will reject any task submitted to it.

Returns:Executor

the rejecting executor instance

rejectingExecutorback to summary
public static Executor rejectingExecutor(final String message)

Get a rejecting executor. This executor will reject any task submitted to it with the given message.

Parameters
message:String

the reject message

Returns:Executor

the rejecting executor instance

rejectingExecutorServiceback to summary
public static ExecutorService rejectingExecutorService()

Get the rejecting executor service. This executor will reject any task submitted to it. It cannot be shut down.

Returns:ExecutorService

the rejecting executor service instance

rejectingExecutorServiceback to summary
public static ExecutorService rejectingExecutorService(final 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:String

the reject message

Returns:ExecutorService

the rejecting executor service instance

resettingThreadFactoryback to summary
public static ThreadFactory resettingThreadFactory(final ThreadFactory delegate) throws SecurityException

Create a thread factory which resets all thread-local storage and delegates to the given thread factory. You must have the RuntimePermission("modifyThread") permission to use this method.

Parameters
delegate:ThreadFactory

the delegate thread factory

Returns:ThreadFactory

the resetting thread factory

Exceptions
SecurityException:
if the caller does not have the RuntimePermission("modifyThread") permission
setContextClassLoaderback to summary
pack-priv static void setContextClassLoader(final Thread thread, final ClassLoader classLoader)

Privileged method to set the context class loader of the given thread.

Parameters
thread:Thread

the thread to introspect

classLoader:ClassLoader

the new context class loader