All Downloads are FREE. Search and download functionalities are using the official Maven repository.

aima.core.util.CancelableThread Maven / Gradle / Ivy

Go to download

AIMA-Java Core Algorithms from the book Artificial Intelligence a Modern Approach 3rd Ed.

The newest version!
package aima.core.util;

/**
 * Implements a thread with an additional flag indicating cancellation.
 * 
 * @author Ruediger Lunde
 * @author Mike Stampone
 */
public class CancelableThread extends Thread {

	public CancelableThread() {
	}
	
	public CancelableThread(Runnable runnable) {
		super(runnable);
	}
	
	/**
	 * 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 - 2024 Weber Informatics LLC | Privacy Policy