public class ServiceThread
extends Thread
Modifier and Type | Class and Description |
---|---|
static class |
ServiceThread.SilentException
Silent exception.
|
static interface |
ServiceThread.Target
Target.
|
Constructor and Description |
---|
ServiceThread(ServiceThread.Target target,
String name)
Constructs an instance.
|
ServiceThread(String name)
Constructs an instance.
|
Modifier and Type | Method and Description |
---|---|
void |
execute(ServiceThread.Target target)
Exeecutes a target.
|
static void |
failed()
Called by
run() to indicate failure. |
Optional<Throwable> |
getThrowable()
Gets the throwable.
|
boolean |
hasFailed()
Asks if this thread has failed.
|
boolean |
interruptAndJoin(Logger logger,
long joinTimeout)
Interrupts this thread and waits for its death.
|
boolean |
join(Logger logger,
long timeout)
Waits for the death of this thread.
|
static void |
ready()
Called to allow a waiting
start(boolean) to complete. |
void |
run() |
void |
setLogger(Logger logger)
Sets the logger.
|
void |
setQuiet(boolean quiet)
Sets the quiet indicator.
|
void |
start() |
boolean |
start(boolean wait)
Starts this thread.
|
boolean |
waitForReady()
Waits for a call to
ready() . |
static void |
yieldAll()
Yields control to other threads, including those of lower priority.
|
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, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, stop, stop, suspend, toString, yield
public ServiceThread(@Nonnull String name)
name
- The thread name.public ServiceThread(@Nonnull ServiceThread.Target target, @Nonnull String name)
target
- The service thread target.name
- The thread name.public static void failed()
run()
to indicate failure.public static void ready()
start(boolean)
to complete.public static void yieldAll()
public void execute(@Nonnull ServiceThread.Target target)
target
- The target.@Nonnull @CheckReturnValue public Optional<Throwable> getThrowable()
@CheckReturnValue public boolean hasFailed()
@CheckReturnValue public boolean interruptAndJoin(@Nonnull Logger logger, long joinTimeout)
logger
- A logger.joinTimeout
- The join timeout in millis (0 means infinite).@CheckReturnValue public boolean join(@Nonnull Logger logger, long timeout)
logger
- A logger.timeout
- The timeout in millis (0 means infinite).public void run()
run
in interface Runnable
run
in class Thread
public void setLogger(@Nonnull Logger logger)
logger
- The logger.public void setQuiet(boolean quiet)
quiet
- The quiet indicator.public void start()
start
in class Thread
@CheckReturnValue public boolean start(boolean wait)
@CheckReturnValue public boolean waitForReady()
ready()
.hasFailed()
or interrupted.Copyright © 2003-2019 Serge Brisson. All Rights Reserved.