Class JBossThread

java.lang.Object
java.lang.Thread
org.jboss.threads.JBossThread
All Implemented Interfaces:
Runnable

public class JBossThread extends Thread
A JBoss thread. Supports logging and extra operations.
  • Constructor Details

  • Method Details

    • interrupt

      public void interrupt()
      Interrupt this thread. Logs a trace message and calls the current interrupt handler, if any. The interrupt handler is called from the calling thread, not the thread being interrupted.
      Overrides:
      interrupt in class Thread
    • isInterrupted

      public boolean isInterrupted()
      Overrides:
      isInterrupted in class Thread
    • executeWithInterruptDeferred

      public static void executeWithInterruptDeferred(Runnable task)
      Defer interrupts for the duration of some task. Once the task is complete, any deferred interrupt will be delivered to the thread, thus the thread interrupt status should be checked upon return. If the current thread is not a JBossThread, the task is simply run as-is.
      Parameters:
      task - the task to run
    • executeWithInterruptDeferred

      public static <T> T executeWithInterruptDeferred(Callable<T> action) throws Exception
      Defer interrupts for the duration of some task. Once the task is complete, any deferred interrupt will be delivered to the thread, thus the thread interrupt status should be checked upon return. If the current thread is not a JBossThread, the task is simply run as-is.
      Type Parameters:
      T - the callable's return type
      Parameters:
      action - the task to run
      Returns:
      the value returned from the callable
      Throws:
      Exception - if the action throws an exception
    • executeWithInterruptDeferred

      public static <T> T executeWithInterruptDeferred(PrivilegedAction<T> action)
      Defer interrupts for the duration of some task. Once the task is complete, any deferred interrupt will be delivered to the thread, thus the thread interrupt status should be checked upon return. If the current thread is not a JBossThread, the task is simply run as-is.
      Type Parameters:
      T - the action's return type
      Parameters:
      action - the task to run
      Returns:
      the value returned from the callable
    • executeWithInterruptDeferred

      public static <T> T executeWithInterruptDeferred(PrivilegedExceptionAction<T> action) throws Exception
      Defer interrupts for the duration of some task. Once the task is complete, any deferred interrupt will be delivered to the thread, thus the thread interrupt status should be checked upon return. If the current thread is not a JBossThread, the task is simply run as-is.
      Type Parameters:
      T - the action's return type
      Parameters:
      action - the task to run
      Returns:
      the value returned from the callable
      Throws:
      Exception - if the action throws an exception
    • applyInterruptDeferredEx

      public static <T, U, R, E extends Exception> R applyInterruptDeferredEx(org.wildfly.common.function.ExceptionBiFunction<T,U,R,E> function, T param1, U param2) throws E
      Throws:
      E extends Exception
    • applyInterruptDeferredEx

      public static <T, R, E extends Exception> R applyInterruptDeferredEx(org.wildfly.common.function.ExceptionFunction<T,R,E> function, T param) throws E
      Throws:
      E extends Exception
    • getInterruptDeferredEx

      public static <T, E extends Exception> T getInterruptDeferredEx(org.wildfly.common.function.ExceptionSupplier<T,E> supplier) throws E
      Throws:
      E extends Exception
    • acceptInterruptDeferredEx

      public static <T, E extends Exception> void acceptInterruptDeferredEx(org.wildfly.common.function.ExceptionObjLongConsumer<T,E> consumer, T param1, long param2) throws E
      Throws:
      E extends Exception
    • acceptInterruptDeferredEx

      public static <T, E extends Exception> void acceptInterruptDeferredEx(org.wildfly.common.function.ExceptionObjIntConsumer<T,E> consumer, T param1, int param2) throws E
      Throws:
      E extends Exception
    • acceptInterruptDeferredEx

      public static <T, U, E extends Exception> void acceptInterruptDeferredEx(org.wildfly.common.function.ExceptionBiConsumer<T,U,E> consumer, T param1, U param2) throws E
      Throws:
      E extends Exception
    • acceptInterruptDeferredEx

      public static <T, E extends Exception> void acceptInterruptDeferredEx(org.wildfly.common.function.ExceptionConsumer<T,E> consumer, T param) throws E
      Throws:
      E extends Exception
    • runInterruptDeferredEx

      public static <E extends Exception> void runInterruptDeferredEx(org.wildfly.common.function.ExceptionRunnable<E> runnable) throws E
      Throws:
      E extends Exception
    • applyInterruptResumedEx

      public static <T, U, R, E extends Exception> R applyInterruptResumedEx(org.wildfly.common.function.ExceptionBiFunction<T,U,R,E> function, T param1, U param2) throws E
      Throws:
      E extends Exception
    • applyInterruptResumedEx

      public static <T, R, E extends Exception> R applyInterruptResumedEx(org.wildfly.common.function.ExceptionFunction<T,R,E> function, T param) throws E
      Throws:
      E extends Exception
    • getInterruptResumedEx

      public static <T, E extends Exception> T getInterruptResumedEx(org.wildfly.common.function.ExceptionSupplier<T,E> supplier) throws E
      Throws:
      E extends Exception
    • acceptInterruptResumedEx

      public static <T, E extends Exception> void acceptInterruptResumedEx(org.wildfly.common.function.ExceptionObjLongConsumer<T,E> consumer, T param1, long param2) throws E
      Throws:
      E extends Exception
    • acceptInterruptResumedEx

      public static <T, E extends Exception> void acceptInterruptResumedEx(org.wildfly.common.function.ExceptionObjIntConsumer<T,E> consumer, T param1, int param2) throws E
      Throws:
      E extends Exception
    • acceptInterruptResumedEx

      public static <T, U, E extends Exception> void acceptInterruptResumedEx(org.wildfly.common.function.ExceptionBiConsumer<T,U,E> consumer, T param1, U param2) throws E
      Throws:
      E extends Exception
    • acceptInterruptResumedEx

      public static <T, E extends Exception> void acceptInterruptResumedEx(org.wildfly.common.function.ExceptionConsumer<T,E> consumer, T param) throws E
      Throws:
      E extends Exception
    • runInterruptResumedEx

      public static <E extends Exception> void runInterruptResumedEx(org.wildfly.common.function.ExceptionRunnable<E> runnable) throws E
      Throws:
      E extends Exception
    • run

      public void run()
      Execute the thread's Runnable. Logs a trace message at the start and end of execution and runs exit handlers when the thread exits.
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • onExit

      public static boolean onExit(Runnable hook) throws SecurityException
      Register a runnable task to be executed when the current thread exits.
      Parameters:
      hook - the task to run
      Returns:
      true if the task was registered; false if the task is null or if the current thread is not an instance of JBossThread
      Throws:
      SecurityException - if a security manager is installed and the caller's security context lacks the modifyThread RuntimePermission
    • currentThread

      public static JBossThread currentThread()
      Get the current JBossThread, or null if the current thread is not a JBossThread.
      Returns:
      the current thread, or null
    • start

      public void start()
      Start the thread.
      Overrides:
      start in class Thread
      Throws:
      IllegalThreadStateException - if the thread was already started.
    • setUncaughtExceptionHandler

      public void setUncaughtExceptionHandler(Thread.UncaughtExceptionHandler eh)
      Change the uncaught exception handler for this thread.
      Overrides:
      setUncaughtExceptionHandler in class Thread
      Parameters:
      eh - the new handler
    • getAndSetInterruptHandler

      public static InterruptHandler getAndSetInterruptHandler(InterruptHandler newInterruptHandler)
      Swap the current thread's active interrupt handler. Most callers should restore the old handler in a finally block like this:
       InterruptHandler oldHandler = JBossThread.getAndSetInterruptHandler(newHandler);
       try {
           ...execute interrupt-sensitive operation...
       } finally {
           JBossThread.getAndSetInterruptHandler(oldHandler);
       }
       
      Parameters:
      newInterruptHandler - the new interrupt handler
      Returns:
      the old interrupt handler
    • applyWithInterruptHandler

      public static <T, U, R, E extends Exception> R applyWithInterruptHandler(InterruptHandler interruptHandler, org.wildfly.common.function.ExceptionBiFunction<T,U,R,E> function, T param1, U param2) throws E
      Throws:
      E extends Exception
    • applyWithInterruptHandler

      public static <T, R, E extends Exception> R applyWithInterruptHandler(InterruptHandler interruptHandler, org.wildfly.common.function.ExceptionFunction<T,R,E> function, T param1) throws E
      Throws:
      E extends Exception
    • getWithInterruptHandler

      public static <R, E extends Exception> R getWithInterruptHandler(InterruptHandler interruptHandler, org.wildfly.common.function.ExceptionSupplier<R,E> function) throws E
      Throws:
      E extends Exception
    • acceptWithInterruptHandler

      public static <T, E extends Exception> void acceptWithInterruptHandler(InterruptHandler interruptHandler, org.wildfly.common.function.ExceptionObjLongConsumer<T,E> function, T param1, long param2) throws E
      Throws:
      E extends Exception
    • acceptWithInterruptHandler

      public static <T, E extends Exception> void acceptWithInterruptHandler(InterruptHandler interruptHandler, org.wildfly.common.function.ExceptionObjIntConsumer<T,E> function, T param1, int param2) throws E
      Throws:
      E extends Exception
    • acceptWithInterruptHandler

      public static <T, U, E extends Exception> void acceptWithInterruptHandler(InterruptHandler interruptHandler, org.wildfly.common.function.ExceptionBiConsumer<T,U,E> function, T param1, U param2) throws E
      Throws:
      E extends Exception
    • acceptWithInterruptHandler

      public static <T, E extends Exception> void acceptWithInterruptHandler(InterruptHandler interruptHandler, org.wildfly.common.function.ExceptionConsumer<T,E> function, T param1) throws E
      Throws:
      E extends Exception
    • runWithInterruptHandler

      public static <E extends Exception> void runWithInterruptHandler(InterruptHandler interruptHandler, org.wildfly.common.function.ExceptionRunnable<E> function) throws E
      Throws:
      E extends Exception