public class ShutdownableThread extends java.lang.Object implements ThreadLike, Shutdownable
runnable in a new thread and another shutdown runnable the
graceful shutdown() phase of the thread. The thread is started immediately upon construction.| Modifier | Constructor and Description |
|---|---|
protected |
ShutdownableThread(RunnableFactory mainRunnableFactory,
RunnableFactory shutdownRunnableFactory,
java.util.concurrent.ThreadFactory threadFactory)
Constructor for shutdownable thread; it is recommended to use the static start(..) methods instead.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
awaitTermination(long timeout,
java.util.concurrent.TimeUnit unit)
Blocks until this service has terminated, or the timeout occurs, whichever happens first.
|
boolean |
isShutdown()
Returns
true if this service has been shut down. |
boolean |
isTerminated()
Returns true if the underlying thread has terminated.
|
void |
join(long millis)
Delegates to
awaitTermination(long, TimeUnit). |
void |
shutdown()
Initiates an orderly shutdown in which the service will be continue to perform its duties
as long as there is work to be done.
|
java.util.List<java.lang.Runnable> |
shutdownNow()
Initiates an immediate shutdown in which the service will stop even if there is more work
to be done.
|
static ShutdownableThread |
start(RunnableFactory mainRunnableFactory,
RunnableFactory shutdownRunnableFactory,
java.util.concurrent.ThreadFactory threadFactory)
Creates, starts and returns a new shutdownable thread.
|
void |
stop()
Calls
shutdown(). |
java.lang.Thread.State |
threadState()
Returns the state of the underlying thread.
|
java.lang.String |
toString()
Returns the name of the thread that was created with the thread factory passed to the constructor.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitisRunningprotected ShutdownableThread(RunnableFactory mainRunnableFactory, RunnableFactory shutdownRunnableFactory, java.util.concurrent.ThreadFactory threadFactory)
mainRunnableFactory - the factory for the main runnable;
the keepMainRunning() condition is passed to the factory as lambdashutdownRunnableFactory - the factory for the shutdown phase runnable;
the keepShutdownRunning() condition is passed to the factory as lambdathreadFactory - the factory to provide the threadpublic static ShutdownableThread start(RunnableFactory mainRunnableFactory, RunnableFactory shutdownRunnableFactory, java.util.concurrent.ThreadFactory threadFactory)
mainRunnableFactory - the factory for the main runnable;
the keepMainRunning() condition is passed to the factory as lambdashutdownRunnableFactory - the factory for the shutdown phase runnable;
the keepShutdownRunning() condition is passed to the factory as lambdathreadFactory - the factory to provide the threadpublic void shutdown()
Shutdownableperform() methods until all invocations
yield false (indicating that no work was done).
This method does not wait for for termination; use awaitTermination
to do that.
Invocation has no additional effect if already shut down.
shutdown in interface Shutdownablepublic java.util.List<java.lang.Runnable> shutdownNow()
Shutdownableperform() irrespective of prior invocation results.
This method does not wait for for termination; use awaitTermination
to do that.
Invocation has no additional effect if already shut down.
shutdownNow in interface Shutdownablepublic boolean isShutdown()
Shutdownabletrue if this service has been shut down.isShutdown in interface Shutdownabletrue if this service has been shut downpublic boolean isTerminated()
ThreadStateisTerminated in interface ShutdownableisTerminated in interface ThreadStatethread state is TERMINATEDpublic boolean awaitTermination(long timeout, java.util.concurrent.TimeUnit unit)
ShutdownableawaitTermination in interface Shutdownabletimeout - the maximum time to wait, zero to wait indefinitelyunit - the time unit of the timeout argumenttrue if this executor terminated and
false if the timeout elapsed before terminationpublic java.lang.Thread.State threadState()
ThreadStatethreadState in interface ThreadStateThread.getState()public void stop()
shutdown().public void join(long millis)
awaitTermination(long, TimeUnit).public java.lang.String toString()
toString in class java.lang.ObjectThread.getName()