
aima.core.util.CancelableThread Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aima-core Show documentation
Show all versions of aima-core Show documentation
AIMA-Java Core Algorithms from the book Artificial Intelligence a Modern Approach 3rd Ed.
package aima.core.util;
/**
* Implements a thread with an additional flag indicating cancellation.
*
* @author R. Lunde
* @author Mike Stampone
*/
public class CancelableThread extends Thread {
/**
* Returns true
if the current thread is canceled
*
* @return true
if the current thread is canceled
*/
public static boolean currIsCanceled() {
if (Thread.currentThread() instanceof CancelableThread)
return ((CancelableThread) Thread.currentThread()).isCanceled;
return false;
}
private volatile boolean isCanceled;
/**
* Returns true
if this thread is canceled
*
* @return true
if this thread is canceled
*/
public boolean isCanceled() {
return isCanceled;
}
/**
* Cancels this thread
*/
public void cancel() {
isCanceled = true;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy