Class CancellableThread
java.lang.Object
java.lang.Thread
com.xinapse.util.CancellableThread
- All Implemented Interfaces:
Runnable
A class to implement a cancellable Thread.
Thread cancellation is achieved by setting the flag. It is up to the thread's
run method to check this flag periodically and return if set.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA flag that can be set to indicate that a cancellation has taken place.Nested classes/interfaces inherited from class Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringA String used to report cancellation.static final StringA String used to report interruption.static final StringA String used to report unexpected cancellation.Fields inherited from class Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Method Summary
Modifier and TypeMethodDescriptionvoidcancel()Signal theCancellableThreadto stop any processing and return.booleanTests whether thisCancellableThreadhas been cancelled.voidrun()Methods inherited from class Thread
activeCount, checkAccess, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, threadId, toString, yield
-
Field Details
-
CANCELLED_MESSAGE
-
INTERRUPTED_MESSAGE
-
UNEXPECTED_CANCELLATION_MESSAGE
A String used to report unexpected cancellation.- See Also:
-
-
Method Details
-
run
-
cancel
public void cancel()Signal theCancellableThreadto stop any processing and return. -
isCancelled
public boolean isCancelled()Tests whether thisCancellableThreadhas been cancelled.- Returns:
trueif thisCancellableThreadhas been cancelled by the user;falseotherwise.
-