Agent System POND 1.2 (28.2.2002)

FIM.Util.Threads
Class CancellableThread

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--FIM.Util.Threads.CancellableThread
All Implemented Interfaces:
Runnable
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).

Version:
1.0, 1.7.2000
Author:
Michael Sonntag

Fields inherited from class java.lang.Thread
inheritableThreadLocals, MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY, threadLocals
 
Constructor Summary
CancellableThread()
           
 
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

CancellableThread

public CancellableThread()
Method Detail

cancel

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

isCancelled

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

terminate

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.
Parameters:
maxWaitToDie - number of seconds to wait for the thread to stop gracefully
Returns:
true if the thread is stopped (false: continues to run)

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.
Overrides:
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.