Agent System POND 1.2 (28.2.2002)

Class CancellableThread

All Implemented Interfaces:
Direct Known Subclasses:
AgentBase, AgentSystem, ServingThread

public abstract class CancellableThread
extends Thread

A thread which can be cancelled by another thread. If it does not want to die, its priority is set to a minimum (Thread.stop() is deprecated).

1.0, 1.7.2000
Michael Sonntag

Fields inherited from class java.lang.Thread
inheritableThreadLocals, MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY, threadLocals
Constructor Summary
Method Summary
 void cancel()
          Cancel this thread.
 boolean isCancelled()
          Returns true if this thread-object (not the current thread!)
abstract  void run()
          Main method of the thread.
 boolean terminate(long maxWaitToDie)
          Cancels this tread and wait till it has stopped (or it is impossible).
Methods inherited from class java.lang.Thread
, activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Constructor Detail


public CancellableThread()
Method Detail


public void cancel()
Cancel this thread. Will try to stop it, but returns immediately.


public boolean isCancelled()
Returns true if this thread-object (not the current thread!) is cancelled.
if this thread is cancelled


public boolean terminate(long maxWaitToDie)
Cancels this tread and wait till it has stopped (or it is impossible). Will wait for a number of seconds or indefinitely (called with 0). If called from within the thread a ThreadDeath error will be thrown if it dies not gracefully.
maxWaitToDie - number of seconds to wait for the thread to stop gracefully
true if the thread is stopped (false: continues to run)


public abstract void run()
Main method of the thread. Subclasses must override and place funtion in here. Any subclasses should regularly check if this thread is cancelled, especially when a wait was interrupted.
run in class Thread

Agent System POND 1.2 (28.2.2002)

Submit a bug

Copyright 2001,2002 Michael Sonntag & Institute for Information Processing and Microprocessor Technology (FIM), Johannes-Kepler-University Linz, Altenbergerstr. 69, A-4040 Linz, Austria.