public class CleaningThread extends Thread
Thread.State, Thread.UncaughtExceptionHandlerMAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY| Constructor and Description |
|---|
CleaningThread(Runnable target)
Constructs a new CleaningThread with the specified target Runnable.
|
CleaningThread(Runnable target,
String name)
Constructs a new CleaningThread with the specified target Runnable and name.
|
CleaningThread(Runnable target,
String name,
boolean inEventLoop)
Constructs a new CleaningThread with the specified target Runnable, name, and inEventLoop flag.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
inEventLoop()
Returns the inEventLoop flag, indicating whether this thread is in an event loop.
|
static boolean |
inEventLoop(Thread t)
Checks if the given thread is an instance of CleaningThread and if it is in an event loop.
|
static void |
performCleanup(Thread thread)
Cleans up any
CleaningThreadLocal associated with the given thread. |
static void |
performCleanup(Thread thread,
CleaningThreadLocal<?> ctl)
Cleans up a specific
CleaningThreadLocal instance associated with the given thread. |
void |
run()
Overrides the run method to reset the thread affinity, execute the target runnable
and then perform clean up of thread locals.
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yieldpublic CleaningThread(Runnable target)
target - The Runnable object to execute in the new thread.public CleaningThread(Runnable target, String name)
target - The Runnable object to execute in the new thread.name - The name for the new thread.public CleaningThread(Runnable target, String name, boolean inEventLoop)
target - The Runnable object to execute in the new thread.name - The name for the new thread.inEventLoop - The flag indicating whether the thread is in an event loop.public static void performCleanup(Thread thread)
CleaningThreadLocal associated with the given thread.
This method uses reflection to find the thread locals for a thread and navigates through a
WeakReference to get to its destination. Note that if a garbage collection has occurred,
this method may not be able to clean up effectively.thread - The thread whose CleaningThreadLocal instances are to be cleaned up.public static void performCleanup(Thread thread, CleaningThreadLocal<?> ctl)
CleaningThreadLocal instance associated with the given thread.thread - The thread whose specific CleaningThreadLocal instance is to be cleaned up.ctl - The specific CleaningThreadLocal instance to clean up. If null, cleans all.public static boolean inEventLoop(Thread t)
t - The thread to check.public void run()
public boolean inEventLoop()
Copyright © 2024. All rights reserved.