public abstract class StoppableThread extends Thread
Thread.State, Thread.UncaughtExceptionHandler| Modifier and Type | Field and Description |
|---|---|
protected EnvironmentImpl |
envImpl |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY| Modifier | Constructor and Description |
|---|---|
protected |
StoppableThread(EnvironmentImpl envImpl,
String threadName) |
protected |
StoppableThread(EnvironmentImpl envImpl,
Thread.UncaughtExceptionHandler handler,
Runnable runnable,
String threadName) |
protected |
StoppableThread(EnvironmentImpl envImpl,
Thread.UncaughtExceptionHandler handler,
String threadName) |
protected |
StoppableThread(String threadName) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
cleanup()
Must be invoked upon, or soon after, exit from the thread to perform
any cleanup, and ensure that any allocated resources are freed.
|
protected abstract Logger |
getLogger() |
Exception |
getSavedShutdownException()
Returns the exception if any that provoked the shutdown
|
long |
getTotalCpuTime()
Returns the total cpu time associated with the thread, after the thread
has been shutdown.
|
long |
getTotalUserTime()
Returns the total cpu time associated with the thread, after the thread
has been shutdown.
|
static void |
handleUncaughtException(Logger useLogger,
EnvironmentImpl envImpl,
Thread t,
Throwable e) |
protected int |
initiateSoftShutdown()
Threads that use shutdownThread() must define this method.
|
boolean |
isShutdown() |
void |
saveShutdownException(Exception shutdownException) |
protected boolean |
shutdownDone(Logger logger)
If the shutdown flag is false, set it to true and return false; in this
case the caller should perform shutdown, including calling
shutdownThread(java.util.logging.Logger). |
void |
shutdownThread(Logger logger)
This method is invoked from another thread of control to shutdown this
thread.
|
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, run, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yieldprotected final EnvironmentImpl envImpl
protected StoppableThread(String threadName)
protected StoppableThread(EnvironmentImpl envImpl, String threadName)
protected StoppableThread(EnvironmentImpl envImpl, Thread.UncaughtExceptionHandler handler, String threadName)
protected StoppableThread(EnvironmentImpl envImpl, Thread.UncaughtExceptionHandler handler, Runnable runnable, String threadName)
protected abstract Logger getLogger()
public Exception getSavedShutdownException()
public void saveShutdownException(Exception shutdownException)
public boolean isShutdown()
protected boolean shutdownDone(Logger logger)
shutdownThread(java.util.logging.Logger). If the shutdown flag is true, wait for this thread to
exit and return true; in this case the caller should not perform
shutdown.
When shutdownDone is initially called by thread X (including from the
run method of the thread being shutdown), then a thread Y calling
shutdownDone should simply return without performing shutdown (this is
when shutdownDone returns true). In this case it is important that this
method calls waitForExit(java.util.logging.Logger) in thread Y to ensure that thread X
really dies, or that an EnvironmentWedgedException is thrown if X does
not die. In particular it is important that all JE threads have died and
released their resources when Environment.close returns to the app
thread, or that EWE is thrown if any JE threads have not died. This
allows the app to reliably re-open the env, or exit the process if
necessary. [#25648]
Note than when thread X has sub-components and manages their threads,
thread X's shutdown method will call shutdown for its managed threads.
Waiting for exit of thread X will therefore wait for exit of its managed
threads, assuming that all shutdown methods calls shutdownDone as
described.logger - the logger on which to log messagesprotected void cleanup()
public static void handleUncaughtException(Logger useLogger, EnvironmentImpl envImpl, Thread t, Throwable e)
public void shutdownThread(Logger logger)
initiateSoftShutdown(). This is the technique of choice.
Each StoppableThread is expected to make provisions for a clean shutdown
via this method. The techniques used to implement this method may vary
based upon the specifics of the thread.
2) If that fails it interrupts the thread.
3) If the thread does not respond to the interrupt, it invalidates the
environment.
All Stoppable threads are expected to catch an interrupt, clean up and
then exit. The cleanup may involve invalidation of the environment, if
the thread is not in a position to handle the interrupt cleanly.
If the method has to resort to step 3, it means that thread and other
resources may not have been freed and it would be best to exit and
restart the process itself to ensure they are freed. In this case an
EnvironmentWedgedException is used to invalidate the env, and the EWE
will be thrown when the app calls Environment.close.logger - the logger on which to log messagesprotected int initiateSoftShutdown()
public long getTotalCpuTime()
public long getTotalUserTime()
Copyright © 2024. All rights reserved.