Package org.jboss.threads
Class JBossThread
java.lang.Object
java.lang.Thread
org.jboss.threads.JBossThread
- All Implemented Interfaces:
Runnable
A JBoss thread. Supports logging and extra operations.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionJBossThread(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
Modifier and TypeMethodDescriptionstatic <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 JBossThreadGet the currentJBossThread, ornullif the current thread is not aJBossThread.static voidDefer interrupts for the duration of some task.static <T> TexecuteWithInterruptDeferred(PrivilegedAction<T> action) Defer interrupts for the duration of some task.static <T> TDefer 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 this thread.booleanstatic booleanRegister 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) voidChange the uncaught exception handler for this thread.voidstart()Start the thread.Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupted, isAlive, isDaemon, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, sleep, sleep, sleep, startVirtualThread, stop, suspend, threadId, toString, yield
-
Constructor Details
-
JBossThread
Construct a new instance.- Parameters:
target- the runnable target- See Also:
-
JBossThread
Construct a new instance.- Parameters:
target- the runnable targetname- the initial thread name- See Also:
-
JBossThread
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:
-
JBossThread
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:
-
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:
-
-
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. -
isInterrupted
public boolean isInterrupted()- Overrides:
isInterruptedin classThread
-
executeWithInterruptDeferred
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
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
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 applyInterruptDeferredExR, E extends Exception> (org.wildfly.common.function.ExceptionBiFunction<T, U, throws ER, E> function, T param1, U param2) - Throws:
E
-
applyInterruptDeferredEx
public static <T,R, R applyInterruptDeferredExE extends Exception> (org.wildfly.common.function.ExceptionFunction<T, R, throws EE> function, T param) - Throws:
E
-
getInterruptDeferredEx
public static <T,E extends Exception> T getInterruptDeferredEx(org.wildfly.common.function.ExceptionSupplier<T, E> supplier) throws E- Throws:
E
-
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
-
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
-
acceptInterruptDeferredEx
public static <T,U, void acceptInterruptDeferredExE extends Exception> (org.wildfly.common.function.ExceptionBiConsumer<T, U, throws EE> consumer, T param1, U param2) - Throws:
E
-
acceptInterruptDeferredEx
public static <T,E extends Exception> void acceptInterruptDeferredEx(org.wildfly.common.function.ExceptionConsumer<T, E> consumer, T param) throws E- Throws:
E
-
runInterruptDeferredEx
public static <E extends Exception> void runInterruptDeferredEx(org.wildfly.common.function.ExceptionRunnable<E> runnable) throws E - Throws:
E
-
applyInterruptResumedEx
public static <T,U, R applyInterruptResumedExR, E extends Exception> (org.wildfly.common.function.ExceptionBiFunction<T, U, throws ER, E> function, T param1, U param2) - Throws:
E
-
applyInterruptResumedEx
public static <T,R, R applyInterruptResumedExE extends Exception> (org.wildfly.common.function.ExceptionFunction<T, R, throws EE> function, T param) - Throws:
E
-
getInterruptResumedEx
public static <T,E extends Exception> T getInterruptResumedEx(org.wildfly.common.function.ExceptionSupplier<T, E> supplier) throws E- Throws:
E
-
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
-
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
-
acceptInterruptResumedEx
public static <T,U, void acceptInterruptResumedExE extends Exception> (org.wildfly.common.function.ExceptionBiConsumer<T, U, throws EE> consumer, T param1, U param2) - Throws:
E
-
acceptInterruptResumedEx
public static <T,E extends Exception> void acceptInterruptResumedEx(org.wildfly.common.function.ExceptionConsumer<T, E> consumer, T param) throws E- Throws:
E
-
runInterruptResumedEx
public static <E extends Exception> void runInterruptResumedEx(org.wildfly.common.function.ExceptionRunnable<E> runnable) throws E - Throws:
E
-
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
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
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
Change the uncaught exception handler for this thread.- Overrides:
setUncaughtExceptionHandlerin classThread- Parameters:
eh- the new handler
-
getAndSetInterruptHandler
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 applyWithInterruptHandlerR, E extends Exception> (InterruptHandler interruptHandler, org.wildfly.common.function.ExceptionBiFunction<T, U, throws ER, E> function, T param1, U param2) - Throws:
E
-
applyWithInterruptHandler
public static <T,R, R applyWithInterruptHandlerE extends Exception> (InterruptHandler interruptHandler, org.wildfly.common.function.ExceptionFunction<T, R, throws EE> function, T param1) - Throws:
E
-
getWithInterruptHandler
public static <R,E extends Exception> R getWithInterruptHandler(InterruptHandler interruptHandler, org.wildfly.common.function.ExceptionSupplier<R, E> function) throws E- Throws:
E
-
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
-
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
-
acceptWithInterruptHandler
public static <T,U, void acceptWithInterruptHandlerE extends Exception> (InterruptHandler interruptHandler, org.wildfly.common.function.ExceptionBiConsumer<T, U, throws EE> function, T param1, U param2) - Throws:
E
-
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
-
runWithInterruptHandler
public static <E extends Exception> void runWithInterruptHandler(InterruptHandler interruptHandler, org.wildfly.common.function.ExceptionRunnable<E> function) throws E - Throws:
E
-