Package com.xinapse.util
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 java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected CancellableThread.FlagThe flag that is set by the cencel() method in order to cancel this Thread.Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcancel()Signal theCancellableThreadto stop any processing and return.booleanTests whether thisCancellableThreadhas been cancelled.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
-
Field Details
-
flag
The flag that is set by the cencel() method in order to cancel this Thread.
-
-
Constructor Details
-
CancellableThread
public CancellableThread()
-
-
Method Details
-
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.
-