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 Details

    • 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 to
      taskClassLoader - the context class loader to use
      Returns:
      the new direct executor
    • abortPolicy

      public static RejectedExecutionHandler abortPolicy()
      Get the abort policy for a ThreadPoolExecutor.
      Returns:
      the abort policy
      See Also:
    • callerRunsPolicy

      public static RejectedExecutionHandler callerRunsPolicy()
      Get the caller-runs policy for a ThreadPoolExecutor.
      Returns:
      the caller-runs policy
      See Also:
    • discardOldestPolicy

      public static RejectedExecutionHandler discardOldestPolicy()
      Get the discard-oldest policy for a ThreadPoolExecutor.
      Returns:
      the discard-oldest policy
      See Also:
    • discardPolicy

      public static RejectedExecutionHandler discardPolicy()
      Get the discard policy for a ThreadPoolExecutor.
      Returns:
      the discard policy
      See Also:
    • handoffPolicy

      public static RejectedExecutionHandler handoffPolicy(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 ExecutorService protectedExecutorService(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
    • protectedScheduledExecutorService

      public static ScheduledExecutorService protectedScheduledExecutorService(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
    • 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 the RuntimePermission("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 the RuntimePermission("modifyThread") permission
    • nullRunnable

      public static Runnable nullRunnable()
      Get the null runnable which does nothing.
      Returns:
      the null runnable
    • contextClassLoaderResetter

      public static Runnable contextClassLoaderResetter()
      Get a Runnable which, 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