Package org.opends.server.api
Class DirectoryThread
- java.lang.Object
-
- java.lang.Thread
-
- org.opends.server.api.DirectoryThread
-
- All Implemented Interfaces:
Runnable
- Direct Known Subclasses:
ChangeNumberIndexer,ConnectionHandler,DirectoryServerShutdownHook,DynamicGroupSearchThread,HeartbeatThread,IdleTimeLimitThread,LDAPRequestHandler,MonitoringPublisher,ParallelWorkerThread,ProfilerThread,ReplayThread,ReplicationServerConnectThread,ReplicationServerListenThread,ServerReader,ServerWriter,Session,ShutdownTaskThread,TaskScheduler,TaskThread,TraditionalWorkerThread
@PublicAPI(stability=VOLATILE, mayInstantiate=true, mayExtend=true, mayInvoke=true) public class DirectoryThread extends Thread
This class defines a generic thread that should be the superclass for all threads created by the Directory Server. That is, instead of having a class that "extends Thread", you should make it "extends DirectoryThread". This provides various value-added capabilities, including:
- It helps make sure that all threads have a human-readable name so they are easier to identify in stack traces.
- It can capture a stack trace from the time that this thread was created that could be useful for debugging purposes.
- It plays an important role in ensuring that log messages generated as part of the processing for Directory Server tasks are properly captured and made available as part of that task.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDirectoryThread.FactoryA factory which can be used by thread pool based services such asExecutors to dynamically create newDirectoryThreadinstances.-
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
-
Field Summary
Fields Modifier and Type Field Description static org.opends.server.api.DirectoryThread.DirectoryThreadGroupDIRECTORY_THREAD_GROUPThe directory thread group that all directory threads will be a member of.-
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
-
Constructor Summary
Constructors Modifier Constructor Description DirectoryThread(Runnable target, String threadName)Creates a new instance of this directory thread with the specified name and with the specified target as its run object.protectedDirectoryThread(String threadName)Creates a new instance of this directory thread with the specified name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TaskgetAssociatedTask()Retrieves the task with which this thread is associated.StackTraceElement[]getCreationStackTrace()Retrieves the stack trace that was captured at the time that this thread was created.Map<String,String>getDebugProperties()Retrieves any relevant debug information with which this tread is associated so they can be included in debug messages.ThreadgetParentThread()Retrieves a reference to the parent thread that created this directory thread.voidinitiateShutdown()Instructs the current thread to initiate the shutdown process.booleanisShutdownInitiated()Returns whether the shutdown process has been initiated on the current thread.voidsetAssociatedTask(Task task)Sets the task with which this thread is associated.voidstartWork()Sets the current thread state to "processing" if the shutdown process was not initiated.voidstopWork()Sets the current thread state to "idle" if the shutdown process was not initiated.-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, run, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Constructor Detail
-
DirectoryThread
public DirectoryThread(Runnable target, String threadName)
Creates a new instance of this directory thread with the specified name and with the specified target as its run object.- Parameters:
target- The target runnable object.threadName- The human-readable name to use for this thread for debugging purposes.
-
DirectoryThread
protected DirectoryThread(String threadName)
Creates a new instance of this directory thread with the specified name.- Parameters:
threadName- The human-readable name to use for this thread for debugging purposes.
-
-
Method Detail
-
getCreationStackTrace
public StackTraceElement[] getCreationStackTrace()
Retrieves the stack trace that was captured at the time that this thread was created.- Returns:
- The stack trace that was captured at the time that this thread was created.
-
getParentThread
public Thread getParentThread()
Retrieves a reference to the parent thread that created this directory thread. That parent thread may or may not be a directory thread.- Returns:
- A reference to the parent thread that created this directory thread.
-
getAssociatedTask
public Task getAssociatedTask()
Retrieves the task with which this thread is associated. This will only be available for threads that are used in the process of running a task.- Returns:
- The task with which this thread is associated, or
nullif there is none.
-
setAssociatedTask
public void setAssociatedTask(Task task)
Sets the task with which this thread is associated. It may benullto indicate that it is not associated with any task.- Parameters:
task- The task with which this thread is associated.
-
getDebugProperties
public Map<String,String> getDebugProperties()
Retrieves any relevant debug information with which this tread is associated so they can be included in debug messages.- Returns:
- debug information about this thread as a string.
-
isShutdownInitiated
public boolean isShutdownInitiated()
Returns whether the shutdown process has been initiated on the current thread. It also returns true when the thread is actually terminated.Waiting for the thread to terminate should be done by invoking one of the
Thread.join()methods.- Returns:
- true if the shutdown process has been initiated on the current thread, false otherwise.
-
initiateShutdown
public void initiateShutdown()
Instructs the current thread to initiate the shutdown process. The actual shutdown of the thread is a best effort and is dependent on the implementation of theThread.run()method.
-
startWork
public void startWork()
Sets the current thread state to "processing" if the shutdown process was not initiated.
-
stopWork
public void stopWork()
Sets the current thread state to "idle" if the shutdown process was not initiated.
-
-