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
Modifier and TypeClassDescriptionstatic class
A 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
Modifier and TypeFieldDescriptionprotected CancellableThread.Flag
The 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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
cancel()
Signal theCancellableThread
to stop any processing and return.boolean
Tests whether thisCancellableThread
has 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 theCancellableThread
to stop any processing and return. -
isCancelled
public boolean isCancelled()Tests whether thisCancellableThread
has been cancelled.- Returns:
true
if thisCancellableThread
has been cancelled by the user;false
otherwise.
-