Package org.jboss.threads
Class JBossThread
- java.lang.Object
-
- java.lang.Thread
-
- org.jboss.threads.JBossThread
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
-
Field Summary
-
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
-
Constructor Summary
Constructors Constructor Description JBossThread(Runnable target)Construct a new instance.JBossThread(Runnable target, String name)Construct a new instance.JBossThread(ThreadGroup group, Runnable target)Construct a new instance.JBossThread(ThreadGroup group, Runnable target, String name)Construct a new instance.JBossThread(ThreadGroup group, Runnable target, String name, long stackSize)Construct a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T,U,E extends Exception>
voidacceptInterruptDeferredEx(org.wildfly.common.function.ExceptionBiConsumer<T,U,E> consumer, T param1, U param2)static <T,E extends Exception>
voidacceptInterruptDeferredEx(org.wildfly.common.function.ExceptionConsumer<T,E> consumer, T param)static <T,E extends Exception>
voidacceptInterruptDeferredEx(org.wildfly.common.function.ExceptionObjIntConsumer<T,E> consumer, T param1, int param2)static <T,E extends Exception>
voidacceptInterruptDeferredEx(org.wildfly.common.function.ExceptionObjLongConsumer<T,E> consumer, T param1, long param2)static <T,U,E extends Exception>
voidacceptInterruptResumedEx(org.wildfly.common.function.ExceptionBiConsumer<T,U,E> consumer, T param1, U param2)static <T,E extends Exception>
voidacceptInterruptResumedEx(org.wildfly.common.function.ExceptionConsumer<T,E> consumer, T param)static <T,E extends Exception>
voidacceptInterruptResumedEx(org.wildfly.common.function.ExceptionObjIntConsumer<T,E> consumer, T param1, int param2)static <T,E extends Exception>
voidacceptInterruptResumedEx(org.wildfly.common.function.ExceptionObjLongConsumer<T,E> consumer, T param1, long param2)static <T,U,E extends Exception>
voidacceptWithInterruptHandler(InterruptHandler interruptHandler, org.wildfly.common.function.ExceptionBiConsumer<T,U,E> function, T param1, U param2)static <T,E extends Exception>
voidacceptWithInterruptHandler(InterruptHandler interruptHandler, org.wildfly.common.function.ExceptionConsumer<T,E> function, T param1)static <T,E extends Exception>
voidacceptWithInterruptHandler(InterruptHandler interruptHandler, org.wildfly.common.function.ExceptionObjIntConsumer<T,E> function, T param1, int param2)static <T,E extends Exception>
voidacceptWithInterruptHandler(InterruptHandler interruptHandler, org.wildfly.common.function.ExceptionObjLongConsumer<T,E> function, T param1, long param2)static <T,U,R,E extends Exception>
RapplyInterruptDeferredEx(org.wildfly.common.function.ExceptionBiFunction<T,U,R,E> function, T param1, U param2)static <T,R,E extends Exception>
RapplyInterruptDeferredEx(org.wildfly.common.function.ExceptionFunction<T,R,E> function, T param)static <T,U,R,E extends Exception>
RapplyInterruptResumedEx(org.wildfly.common.function.ExceptionBiFunction<T,U,R,E> function, T param1, U param2)static <T,R,E extends Exception>
RapplyInterruptResumedEx(org.wildfly.common.function.ExceptionFunction<T,R,E> function, T param)static <T,U,R,E extends Exception>
RapplyWithInterruptHandler(InterruptHandler interruptHandler, org.wildfly.common.function.ExceptionBiFunction<T,U,R,E> function, T param1, U param2)static <T,R,E extends Exception>
RapplyWithInterruptHandler(InterruptHandler interruptHandler, org.wildfly.common.function.ExceptionFunction<T,R,E> function, T param1)static JBossThreadcurrentThread()Get the currentJBossThread, ornullif the current thread is not aJBossThread.static voidexecuteWithInterruptDeferred(Runnable task)Defer interrupts for the duration of some task.static <T> TexecuteWithInterruptDeferred(PrivilegedAction<T> action)Defer interrupts for the duration of some task.static <T> TexecuteWithInterruptDeferred(PrivilegedExceptionAction<T> action)Defer interrupts for the duration of some task.static <T> TexecuteWithInterruptDeferred(Callable<T> action)Defer interrupts for the duration of some task.static InterruptHandlergetAndSetInterruptHandler(InterruptHandler newInterruptHandler)Swap the current thread's active interrupt handler.static <T,E extends Exception>
TgetInterruptDeferredEx(org.wildfly.common.function.ExceptionSupplier<T,E> supplier)static <T,E extends Exception>
TgetInterruptResumedEx(org.wildfly.common.function.ExceptionSupplier<T,E> supplier)static <R,E extends Exception>
RgetWithInterruptHandler(InterruptHandler interruptHandler, org.wildfly.common.function.ExceptionSupplier<R,E> function)voidinterrupt()Interrupt this thread.booleanisInterrupted()static booleanonExit(Runnable hook)Register a runnable task to be executed when the current thread exits.voidrun()Execute the thread'sRunnable.static <E extends Exception>
voidrunInterruptDeferredEx(org.wildfly.common.function.ExceptionRunnable<E> runnable)static <E extends Exception>
voidrunInterruptResumedEx(org.wildfly.common.function.ExceptionRunnable<E> runnable)static <E extends Exception>
voidrunWithInterruptHandler(InterruptHandler interruptHandler, org.wildfly.common.function.ExceptionRunnable<E> function)voidsetUncaughtExceptionHandler(Thread.UncaughtExceptionHandler eh)Change the uncaught exception handler for this thread.voidstart()Start the thread.-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupted, isAlive, isDaemon, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, sleep, sleep, stop, stop, suspend, toString, yield
-
-
-
-
Constructor Detail
-
JBossThread
public JBossThread(Runnable target)
Construct a new instance.- Parameters:
target- the runnable target- See Also:
Thread(Runnable)
-
JBossThread
public JBossThread(Runnable target, String name)
Construct a new instance.- Parameters:
target- the runnable targetname- the initial thread name- See Also:
Thread(Runnable, String)
-
JBossThread
public JBossThread(ThreadGroup group, Runnable target) throws SecurityException
Construct a new instance.- Parameters:
group- the parent thread grouptarget- the runnable target- Throws:
SecurityException- if the current thread cannot create a thread in the specified thread group- See Also:
Thread(ThreadGroup, Runnable)
-
JBossThread
public JBossThread(ThreadGroup group, Runnable target, String name) throws SecurityException
Construct a new instance.- Parameters:
group- the parent thread grouptarget- the runnable targetname- the initial thread name- Throws:
SecurityException- if the current thread cannot create a thread in the specified thread group- See Also:
Thread(ThreadGroup,Runnable,String)
-
JBossThread
public JBossThread(ThreadGroup group, Runnable target, String name, long stackSize) throws SecurityException
Construct a new instance.- Parameters:
group- the parent thread grouptarget- the runnable targetname- the initial thread name- Throws:
SecurityException- if the current thread cannot create a thread in the specified thread group- See Also:
Thread(ThreadGroup,Runnable,String,long)
-
-
Method Detail
-
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.
-
isInterrupted
public boolean isInterrupted()
- Overrides:
isInterruptedin classThread
-
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 aJBossThread, 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 aJBossThread, 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 aJBossThread, 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 aJBossThread, 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 extends Exception
- 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 extends Exception
- Throws:
E extends Exception
-
getInterruptDeferredEx
public static <T,E extends Exception> T getInterruptDeferredEx(org.wildfly.common.function.ExceptionSupplier<T,E> supplier) throws E extends Exception
- 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 extends Exception
- 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 extends Exception
- 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 extends Exception
- 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 extends Exception
- Throws:
E extends Exception
-
runInterruptDeferredEx
public static <E extends Exception> void runInterruptDeferredEx(org.wildfly.common.function.ExceptionRunnable<E> runnable) throws E extends Exception
- 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 extends Exception
- 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 extends Exception
- Throws:
E extends Exception
-
getInterruptResumedEx
public static <T,E extends Exception> T getInterruptResumedEx(org.wildfly.common.function.ExceptionSupplier<T,E> supplier) throws E extends Exception
- 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 extends Exception
- 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 extends Exception
- 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 extends Exception
- 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 extends Exception
- Throws:
E extends Exception
-
runInterruptResumedEx
public static <E extends Exception> void runInterruptResumedEx(org.wildfly.common.function.ExceptionRunnable<E> runnable) throws E extends Exception
- Throws:
E extends Exception
-
run
public void run()
Execute the thread'sRunnable. Logs a trace message at the start and end of execution and runs exit handlers when the thread exits.
-
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:
trueif the task was registered;falseif the task isnullor if the current thread is not an instance ofJBossThread- Throws:
SecurityException- if a security manager is installed and the caller's security context lacks themodifyThreadRuntimePermission
-
currentThread
public static JBossThread currentThread()
Get the currentJBossThread, ornullif the current thread is not aJBossThread.- Returns:
- the current thread, or
null
-
start
public void start()
Start the thread.- Overrides:
startin classThread- Throws:
IllegalThreadStateException- if the thread was already started.
-
setUncaughtExceptionHandler
public void setUncaughtExceptionHandler(Thread.UncaughtExceptionHandler eh)
Change the uncaught exception handler for this thread.- Overrides:
setUncaughtExceptionHandlerin classThread- 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 afinallyblock 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 extends Exception
- 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 extends Exception
- 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 extends Exception
- 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 extends Exception
- 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 extends Exception
- 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 extends Exception
- 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 extends Exception
- Throws:
E extends Exception
-
runWithInterruptHandler
public static <E extends Exception> void runWithInterruptHandler(InterruptHandler interruptHandler, org.wildfly.common.function.ExceptionRunnable<E> function) throws E extends Exception
- Throws:
E extends Exception
-
-