Top Description Fields Constructors Methods
org.jboss.threads

public Class JBossThread

extends Thread
Class Inheritance
Imports
java.security.AccessController, .PrivilegedAction, .PrivilegedExceptionAction, java.util.ArrayList, .List, java.util.concurrent.Callable, java.util.concurrent.atomic.AtomicInteger, java.util.concurrent.locks.LockSupport, org.wildfly.common.Assert, org.wildfly.common.cpu.ProcessorInfo, org.wildfly.common.function.ExceptionBiConsumer, .ExceptionBiFunction, .ExceptionConsumer, .ExceptionFunction, .ExceptionObjIntConsumer, .ExceptionObjLongConsumer, .ExceptionRunnable, .ExceptionSupplier, .Functions

A JBoss thread. Supports logging and extra operations.

Field Summary

Modifier and TypeField and Description
private List<Runnable>
private volatile InterruptHandler
private static final int
private static final RuntimePermission
private static final int
STATE_INTERRUPT_DEFERRED

The thread is not interrupted, and interrupts will be deferred.

private static final int
STATE_INTERRUPT_IN_PROGRESS

The thread is in the process of executing interruption logic.

private static final int
STATE_INTERRUPT_PENDING

The thread is not interrupted, but there is an interrupt pending for once deferral is ended.

private static final int
STATE_MAYBE_INTERRUPTED

The thread is maybe interrupted.

private final AtomicInteger
private ThreadNameInfo
Inherited from java.lang.Thread:
MAX_PRIORITYMIN_PRIORITYNORM_PRIORITY

Constructor Summary

AccessConstructor and Description
public
JBossThread(final Runnable
the runnable target
target
)

Construct a new instance.

public
JBossThread(final Runnable
the runnable target
target
,
final String
the initial thread name
name
)

Construct a new instance.

public
JBossThread(final ThreadGroup
the parent thread group
group
,
final Runnable
the runnable target
target
)

Construct a new instance.

public
JBossThread(final ThreadGroup
the parent thread group
group
,
final Runnable
the runnable target
target
,
final String
the initial thread name
name
)

Construct a new instance.

public
JBossThread(final ThreadGroup
the parent thread group
group
,
final Runnable
the runnable target
target
,
final String
the initial thread name
name
,
final long stackSize)

Construct a new instance.

Method Summary

Modifier and TypeMethod and Description
public static <T, E extends Exception> void
acceptInterruptDeferredEx(final ExceptionObjLongConsumer<T, E> consumer, T param1, long param2)

public static <T, E extends Exception> void
acceptInterruptDeferredEx(final ExceptionObjIntConsumer<T, E> consumer, T param1, int param2)

public static <T, U, E extends Exception> void
acceptInterruptDeferredEx(final ExceptionBiConsumer<T, U, E> consumer, T param1, U param2)

public static <T, E extends Exception> void
acceptInterruptDeferredEx(final ExceptionConsumer<T, E> consumer, T param)

public static <T, E extends Exception> void
acceptInterruptResumedEx(final ExceptionObjLongConsumer<T, E> consumer, T param1, long param2)

public static <T, E extends Exception> void
acceptInterruptResumedEx(final ExceptionObjIntConsumer<T, E> consumer, T param1, int param2)

public static <T, U, E extends Exception> void
acceptInterruptResumedEx(final ExceptionBiConsumer<T, U, E> consumer, T param1, U param2)

public static <T, E extends Exception> void
acceptInterruptResumedEx(final ExceptionConsumer<T, E> consumer, T param)

public static <T, E extends Exception> void
acceptWithInterruptHandler(InterruptHandler interruptHandler, ExceptionObjLongConsumer<T, E> function, T param1, long param2)

public static <T, E extends Exception> void
acceptWithInterruptHandler(InterruptHandler interruptHandler, ExceptionObjIntConsumer<T, E> function, T param1, int param2)

public static <T, U, E extends Exception> void
acceptWithInterruptHandler(InterruptHandler interruptHandler, ExceptionBiConsumer<T, U, E> function, T param1, U param2)

public static <T, E extends Exception> void
acceptWithInterruptHandler(InterruptHandler interruptHandler, ExceptionConsumer<T, E> function, T param1)

public static <T, U, R, E extends Exception> R
applyInterruptDeferredEx(final ExceptionBiFunction<T, U, R, E> function, T param1, U param2)

public static <T, R, E extends Exception> R
applyInterruptDeferredEx(final ExceptionFunction<T, R, E> function, T param)

public static <T, U, R, E extends Exception> R
applyInterruptResumedEx(final ExceptionBiFunction<T, U, R, E> function, T param1, U param2)

public static <T, R, E extends Exception> R
applyInterruptResumedEx(final ExceptionFunction<T, R, E> function, T param)

public static <T, U, R, E extends Exception> R
applyWithInterruptHandler(InterruptHandler interruptHandler, ExceptionBiFunction<T, U, R, E> function, T param1, U param2)

public static <T, R, E extends Exception> R
applyWithInterruptHandler(InterruptHandler interruptHandler, ExceptionFunction<T, R, E> function, T param1)

public static JBossThread

Returns:

the current thread, or null
currentThread
()

Hides java.lang.Thread.currentThread.

Get the current JBossThread, or null if the current thread is not a JBossThread.
private void
public static void
executeWithInterruptDeferred(final Runnable
the task to run
task
)

Defer interrupts for the duration of some task.

public static <
the callable's return type
T
>
T

Returns:

the value returned from the callable
executeWithInterruptDeferred
(final Callable<T>
the task to run
action
)

Defer interrupts for the duration of some task.

public static <
the action's return type
T
>
T

Returns:

the value returned from the callable
executeWithInterruptDeferred
(final PrivilegedAction<T>
the task to run
action
)

Defer interrupts for the duration of some task.

public static <
the action's return type
T
>
T

Returns:

the value returned from the callable
executeWithInterruptDeferred
(final PrivilegedExceptionAction<T>
the task to run
action
)

Defer interrupts for the duration of some task.

public static InterruptHandler

Returns:

the old interrupt handler
getAndSetInterruptHandler
(final InterruptHandler
the new interrupt handler
newInterruptHandler
)

Swap the current thread's active interrupt handler.

public static <T, E extends Exception> T
public static <T, E extends Exception> T
pack-priv ThreadNameInfo

Returns:

the thread name info
getThreadNameInfo
()

Get the thread name information.

public static <R, E extends Exception> R
public void
interrupt()

Overrides java.lang.Thread.interrupt.

Interrupt this thread.
public boolean
isInterrupted()

Overrides java.lang.Thread.isInterrupted.

Tests whether this thread has been interrupted.
public static boolean

Returns:

true if the task was registered; false if the task is null or if the current thread is not an instance of JBossThread
onExit
(Runnable
the task to run
hook
)

Register a runnable task to be executed when the current thread exits.

private static boolean
public void
run()

Overrides java.lang.Thread.run.

Implements java.lang.Runnable.run.

Execute the thread's Runnable.
public static <E extends Exception> void
public static <E extends Exception> void
public static <E extends Exception> void
pack-priv void
setThreadNameInfo(final ThreadNameInfo
the new thread name info
threadNameInfo
)

Set the thread name information.

public void
setUncaughtExceptionHandler(final Thread.UncaughtExceptionHandler
the new handler
eh
)

Overrides java.lang.Thread.setUncaughtExceptionHandler.

Change the uncaught exception handler for this thread.
public void
start()

Overrides java.lang.Thread.start.

Start the thread.
private static boolean
Inherited from java.lang.Thread:
activeCountcheckAccessclonecountStackFramesdumpStackenumerategetAllStackTracesgetContextClassLoadergetDefaultUncaughtExceptionHandlergetIdgetNamegetPrioritygetStackTracegetStategetThreadGroupgetUncaughtExceptionHandlerholdsLockinterruptedisAliveisDaemonisVirtualjoinjoinjoinjoinofPlatformofVirtualonSpinWaitresumesetContextClassLoadersetDaemonsetDefaultUncaughtExceptionHandlersetNamesetPrioritysleepsleepsleepstartVirtualThreadstopsuspendthreadIdtoStringyield

Field Detail

exitHandlersback to summary
private List<Runnable> exitHandlers
interruptHandlerback to summary
private volatile InterruptHandler interruptHandler
MAX_INTERRUPT_SPINSback to summary
private static final int MAX_INTERRUPT_SPINS
MODIFY_THREAD_PERMISSIONback to summary
private static final RuntimePermission MODIFY_THREAD_PERMISSION
STATE_INTERRUPT_DEFERREDback to summary
private static final int STATE_INTERRUPT_DEFERRED

The thread is not interrupted, and interrupts will be deferred. Possible transitions:

STATE_INTERRUPT_IN_PROGRESSback to summary
private static final int STATE_INTERRUPT_IN_PROGRESS

The thread is in the process of executing interruption logic. If the thread attempts to defer interrupts during this phase, it will block until the interruption logic is complete.

STATE_INTERRUPT_PENDINGback to summary
private static final int STATE_INTERRUPT_PENDING

The thread is not interrupted, but there is an interrupt pending for once deferral is ended. Possible transitions:

STATE_MAYBE_INTERRUPTEDback to summary
private static final int STATE_MAYBE_INTERRUPTED

The thread is maybe interrupted. Possible transitions:

stateRefback to summary
private final AtomicInteger stateRef
threadNameInfoback to summary
private ThreadNameInfo threadNameInfo

Constructor Detail

JBossThreadback to summary
public JBossThread(final Runnable target)

Construct a new instance.

Parameters
target:Runnable

the runnable target

See Also
Thread#Thread(Runnable)
JBossThreadback to summary
public JBossThread(final Runnable target, final String name)

Construct a new instance.

Parameters
target:Runnable

the runnable target

name:String

the initial thread name

See Also
Thread#Thread(Runnable, String)
JBossThreadback to summary
public JBossThread(final ThreadGroup group, final Runnable target) throws SecurityException

Construct a new instance.

Parameters
group:ThreadGroup

the parent thread group

target:Runnable

the runnable target

Exceptions
SecurityException:
if the current thread cannot create a thread in the specified thread group
See Also
Thread#Thread(ThreadGroup, Runnable)
JBossThreadback to summary
public JBossThread(final ThreadGroup group, final Runnable target, final String name) throws SecurityException

Construct a new instance.

Parameters
group:ThreadGroup

the parent thread group

target:Runnable

the runnable target

name:String

the initial thread name

Exceptions
SecurityException:
if the current thread cannot create a thread in the specified thread group
See Also
Thread#Thread(ThreadGroup, Runnable, String)
JBossThreadback to summary
public JBossThread(final ThreadGroup group, final Runnable target, final String name, final long stackSize) throws SecurityException

Construct a new instance.

Parameters
group:ThreadGroup

the parent thread group

target:Runnable

the runnable target

name:String

the initial thread name

Exceptions
SecurityException:
if the current thread cannot create a thread in the specified thread group
See Also
Thread#Thread(ThreadGroup, Runnable, String, long)

Method Detail

acceptInterruptDeferredExback to summary
public static <T, E extends Exception> void acceptInterruptDeferredEx(final ExceptionObjLongConsumer<T, E> consumer, T param1, long param2) throws ExceptionObjLongConsumer-T-long-:E
acceptInterruptDeferredExback to summary
public static <T, E extends Exception> void acceptInterruptDeferredEx(final ExceptionObjIntConsumer<T, E> consumer, T param1, int param2) throws ExceptionObjIntConsumer-T-int-:E
acceptInterruptDeferredExback to summary
public static <T, U, E extends Exception> void acceptInterruptDeferredEx(final ExceptionBiConsumer<T, U, E> consumer, T param1, U param2) throws ExceptionBiConsumer-T-U-:E
acceptInterruptDeferredExback to summary
public static <T, E extends Exception> void acceptInterruptDeferredEx(final ExceptionConsumer<T, E> consumer, T param) throws ExceptionConsumer-T-:E
acceptInterruptResumedExback to summary
public static <T, E extends Exception> void acceptInterruptResumedEx(final ExceptionObjLongConsumer<T, E> consumer, T param1, long param2) throws ExceptionObjLongConsumer-T-long-:E
acceptInterruptResumedExback to summary
public static <T, E extends Exception> void acceptInterruptResumedEx(final ExceptionObjIntConsumer<T, E> consumer, T param1, int param2) throws ExceptionObjIntConsumer-T-int-:E
acceptInterruptResumedExback to summary
public static <T, U, E extends Exception> void acceptInterruptResumedEx(final ExceptionBiConsumer<T, U, E> consumer, T param1, U param2) throws ExceptionBiConsumer-T-U-:E
acceptInterruptResumedExback to summary
public static <T, E extends Exception> void acceptInterruptResumedEx(final ExceptionConsumer<T, E> consumer, T param) throws ExceptionConsumer-T-:E
acceptWithInterruptHandlerback to summary
public static <T, E extends Exception> void acceptWithInterruptHandler(InterruptHandler interruptHandler, ExceptionObjLongConsumer<T, E> function, T param1, long param2) throws ExceptionObjLongConsumer-T-long-:E
acceptWithInterruptHandlerback to summary
public static <T, E extends Exception> void acceptWithInterruptHandler(InterruptHandler interruptHandler, ExceptionObjIntConsumer<T, E> function, T param1, int param2) throws ExceptionObjIntConsumer-T-int-:E
acceptWithInterruptHandlerback to summary
public static <T, U, E extends Exception> void acceptWithInterruptHandler(InterruptHandler interruptHandler, ExceptionBiConsumer<T, U, E> function, T param1, U param2) throws ExceptionBiConsumer-T-U-:E
acceptWithInterruptHandlerback to summary
public static <T, E extends Exception> void acceptWithInterruptHandler(InterruptHandler interruptHandler, ExceptionConsumer<T, E> function, T param1) throws ExceptionConsumer-T-:E
applyInterruptDeferredExback to summary
public static <T, U, R, E extends Exception> R applyInterruptDeferredEx(final ExceptionBiFunction<T, U, R, E> function, T param1, U param2) throws ExceptionBiFunction-T-U-:E
applyInterruptDeferredExback to summary
public static <T, R, E extends Exception> R applyInterruptDeferredEx(final ExceptionFunction<T, R, E> function, T param) throws ExceptionFunction-T-:E
applyInterruptResumedExback to summary
public static <T, U, R, E extends Exception> R applyInterruptResumedEx(final ExceptionBiFunction<T, U, R, E> function, T param1, U param2) throws ExceptionBiFunction-T-U-:E
applyInterruptResumedExback to summary
public static <T, R, E extends Exception> R applyInterruptResumedEx(final ExceptionFunction<T, R, E> function, T param) throws ExceptionFunction-T-:E
applyWithInterruptHandlerback to summary
public static <T, U, R, E extends Exception> R applyWithInterruptHandler(InterruptHandler interruptHandler, ExceptionBiFunction<T, U, R, E> function, T param1, U param2) throws ExceptionBiFunction-T-U-:E
applyWithInterruptHandlerback to summary
public static <T, R, E extends Exception> R applyWithInterruptHandler(InterruptHandler interruptHandler, ExceptionFunction<T, R, E> function, T param1) throws ExceptionFunction-T-:E
currentThreadback to summary
public static JBossThread currentThread()

Hides java.lang.Thread.currentThread.

Get the current JBossThread, or null if the current thread is not a JBossThread.

Returns:JBossThread

the current thread, or null

doInterruptback to summary
private void doInterrupt()
executeWithInterruptDeferredback to summary
public static void executeWithInterruptDeferred(final 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:Runnable

the task to run

executeWithInterruptDeferredback to summary
public static <T> T executeWithInterruptDeferred(final 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.

Parameters
<T>
the callable's return type
action:Callable<T>

the task to run

Returns:T

the value returned from the callable

Exceptions
Exception:
if the action throws an exception
executeWithInterruptDeferredback to summary
public static <T> T executeWithInterruptDeferred(final 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.

Parameters
<T>
the action's return type
action:PrivilegedAction<T>

the task to run

Returns:T

the value returned from the callable

executeWithInterruptDeferredback to summary
public static <T> T executeWithInterruptDeferred(final 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.

Parameters
<T>
the action's return type
action:PrivilegedExceptionAction<T>

the task to run

Returns:T

the value returned from the callable

Exceptions
Exception:
if the action throws an exception
getAndSetInterruptHandlerback to summary
public static InterruptHandler getAndSetInterruptHandler(final 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:InterruptHandler

the new interrupt handler

Returns:InterruptHandler

the old interrupt handler

getInterruptDeferredExback to summary
public static <T, E extends Exception> T getInterruptDeferredEx(final ExceptionSupplier<T, E> supplier) throws ExceptionSupplier-:E
getInterruptResumedExback to summary
public static <T, E extends Exception> T getInterruptResumedEx(final ExceptionSupplier<T, E> supplier) throws ExceptionSupplier-:E
getThreadNameInfoback to summary
pack-priv ThreadNameInfo getThreadNameInfo()

Get the thread name information. This includes information about the thread's sequence number and so forth.

Returns:ThreadNameInfo

the thread name info

getWithInterruptHandlerback to summary
public static <R, E extends Exception> R getWithInterruptHandler(InterruptHandler interruptHandler, ExceptionSupplier<R, E> function) throws ExceptionSupplier-:E
interruptback to summary
public void interrupt()

Overrides java.lang.Thread.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.

isInterruptedback to summary
public boolean isInterrupted()

Overrides java.lang.Thread.isInterrupted.

Doc from java.lang.Thread.isInterrupted.

Tests whether this thread has been interrupted. The interrupted status of the thread is unaffected by this method.

Returns:boolean

true if this thread has been interrupted; false otherwise.

onExitback to summary
public static boolean onExit(Runnable hook) throws SecurityException

Register a runnable task to be executed when the current thread exits.

Parameters
hook:Runnable

the task to run

Returns:boolean

true if the task was registered; false if the task is null or if the current thread is not an instance of JBossThread

Exceptions
SecurityException:
if a security manager is installed and the caller's security context lacks the modifyThread RuntimePermission
registerDeferralback to summary
private static boolean registerDeferral(final JBossThread thread)
runback to summary
public void run()

Overrides java.lang.Thread.run.

Implements java.lang.Runnable.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.

runInterruptDeferredExback to summary
public static <E extends Exception> void runInterruptDeferredEx(final ExceptionRunnable<E> runnable) throws ExceptionRunnable-:E
runInterruptResumedExback to summary
public static <E extends Exception> void runInterruptResumedEx(final ExceptionRunnable<E> runnable) throws ExceptionRunnable-:E
runWithInterruptHandlerback to summary
public static <E extends Exception> void runWithInterruptHandler(InterruptHandler interruptHandler, ExceptionRunnable<E> function) throws ExceptionRunnable-:E
setThreadNameInfoback to summary
pack-priv void setThreadNameInfo(final ThreadNameInfo threadNameInfo) throws SecurityException

Set the thread name information. This includes information about the thread's sequence number and so forth.

Parameters
threadNameInfo:ThreadNameInfo

the new thread name info

Exceptions
SecurityException:
if the calling thread is not allowed to modify this thread
setUncaughtExceptionHandlerback to summary
public void setUncaughtExceptionHandler(final Thread.UncaughtExceptionHandler eh)

Overrides java.lang.Thread.setUncaughtExceptionHandler.

Change the uncaught exception handler for this thread.

Parameters
eh:Thread.UncaughtExceptionHandler

the new handler

startback to summary
public void start()

Overrides java.lang.Thread.start.

Start the thread.

Exceptions
IllegalThreadStateException:
if the thread was already started.
unregisterDeferralback to summary
private static boolean unregisterDeferral(final JBossThread thread)