Package com.peterphi.std.threading
Class Daemon
java.lang.Object
com.peterphi.std.threading.Daemon
- All Implemented Interfaces:
Runnable
- Direct Known Subclasses:
GuiceDaemon
Simplifies the creation of long-running daemon threads
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionlong
protected String
Return the name for this threadboolean
Returns whether the daemon is in the process of terminatingboolean
Determines if this daemon's thread is aliveprotected void
setTextState
(String value) protected boolean
Overloading this method to return true will start this daemon's thread as a Daemon ThreadStarts this daemon, creating a new thread for it (the name of which will be set to the SimpleName of its class)startThread
(String name) Starts this daemon, creating a new thread for itstatic void
Stop all the daemons in a given list:void
Requests the daemon terminate by setting a flag and sending an interrupt to the threadstatic boolean
waitForTermination
(Daemon daemon, long timeoutMillis) static boolean
waitForTermination
(List<? extends Daemon> daemons, long timeoutMillis)
-
Constructor Details
-
Daemon
public Daemon()
-
-
Method Details
-
startThread
Starts this daemon, creating a new thread for it (the name of which will be set to the SimpleName of its class)- Returns:
- Thread The daemon's thread
- Throws:
IllegalThreadStateException
- If the daemon is still running
-
getThreadName
Return the name for this thread- Returns:
-
getThread
-
startThread
Starts this daemon, creating a new thread for it- Parameters:
name
- String The name for the thread- Returns:
- Thread The daemon's thread
- Throws:
IllegalThreadStateException
- If the daemon is still running
-
getTextState
-
getTextStateUpdated
public long getTextStateUpdated() -
setTextState
-
isRunning
public boolean isRunning()Returns whether the daemon is in the process of terminating- Returns:
- boolean True if the daemon is terminated or terminating, otherwise false
-
stopThread
public void stopThread()Requests the daemon terminate by setting a flag and sending an interrupt to the thread -
isThreadRunning
public boolean isThreadRunning()Determines if this daemon's thread is alive- Returns:
- boolean True if the thread is alive, otherwise false
-
shouldStartAsDaemon
protected boolean shouldStartAsDaemon()Overloading this method to return true will start this daemon's thread as a Daemon Thread- Returns:
- boolean True if the thread should be started as a daemon, otherwise false
-
stopAll
Stop all the daemons in a given list:- Parameters:
daemons
- List[Daemon] The daemons to stop
-
waitForTermination
-
waitForTermination
-