|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Thread
com.sleepycat.je.utilint.StoppableThread
public abstract class StoppableThread
A StoppableThread is a daemon that obeys the following mandates: - it sets the daemon property for the thread - an uncaught exception handler is always registered - the thread registers with the JE exception listener mechanism. - its shutdown method can only be executed once. StoppableThreads are not required to implement shutdown() methods, because in some cases their shutdown processing must be coordinated by an owning, parent thread. StoppableThread is an alternative to the DaemonThread. It also assumes that the thread's run() method may be more complex that that of the work-queue, task oriented DaemonThread. A StoppableThread's run method should catch and handle all exceptions. By default, unhandled exceptions are considered programming errors, and invalidate the environment, but StoppableThreads may supply alternative uncaught exception handling. StoppableThreads usually are created with an EnvironmentImpl, but on occasion an environment may not be available (for components that can execute without an environment). In that case, the thread obviously does not invalidate the environment. Note that the StoppableThread.cleanup must be invoked upon, or soon after, thread exit.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.lang.Thread |
---|
Thread.State, Thread.UncaughtExceptionHandler |
Field Summary | |
---|---|
protected EnvironmentImpl |
envImpl
|
Fields inherited from class java.lang.Thread |
---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
---|---|
protected |
StoppableThread()
|
protected |
StoppableThread(EnvironmentImpl envImpl)
|
protected |
StoppableThread(EnvironmentImpl envImpl,
Thread.UncaughtExceptionHandler handler)
|
Method Summary | |
---|---|
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. |
protected int |
initiateSoftShutdown()
Threads that use shutdownThread() must define this method. |
boolean |
isShutdown()
|
void |
saveShutdownException(Exception shutdownException)
|
void |
setExceptionListener(ExceptionListener exceptionListener)
Set every time a new exception listener is registered. |
protected boolean |
shutdownDone()
Shutdown methods should only be executed once. |
void |
shutdownThread(Logger logger)
This method is invoked from another thread of control to shutdown this thread. |
Methods inherited from class java.lang.Thread |
---|
activeCount, checkAccess, 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, yield |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected final EnvironmentImpl envImpl
Constructor Detail |
---|
protected StoppableThread()
protected StoppableThread(EnvironmentImpl envImpl)
protected StoppableThread(EnvironmentImpl envImpl, Thread.UncaughtExceptionHandler handler)
Method Detail |
---|
protected abstract Logger getLogger()
public Exception getSavedShutdownException()
public void saveShutdownException(Exception shutdownException)
public boolean isShutdown()
public void setExceptionListener(ExceptionListener exceptionListener)
setExceptionListener
in interface ExceptionListenerUser
protected boolean shutdownDone()
protected void cleanup()
public void shutdownThread(Logger logger)
initiateSoftShutdown()
. If the thread does not exit on its
own in waitMs
the thread is interrupted.
waitMs
is determined by the technique used for the soft
shutdown. For example, if the thread polls on a periodic basis, it could
span one or more polling periods.
All Stoppable threads are expected to catch an interrupt, clean up and
then exit.
logger
- the logger on which to log messagesprotected int initiateSoftShutdown()
public long getTotalCpuTime()
public long getTotalUserTime()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |