jj2000.j2k.util
Class ThreadPool.ThreadPoolThread

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--jj2000.j2k.util.ThreadPool.ThreadPoolThread
All Implemented Interfaces:
java.lang.Runnable
Enclosing class:
ThreadPool

class ThreadPool.ThreadPoolThread
extends java.lang.Thread

The threads that are managed by the pool.


Field Summary
private  boolean doNotifyAll
           
private  java.lang.Object lock
           
private  java.lang.Runnable target
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ThreadPool.ThreadPoolThread(int idx, java.lang.String name)
          Creates a ThreadPoolThread object, setting its name according to the given 'idx', daemon type and the priority to the one of the pool.
 
Method Summary
 void run()
          The method that is run by the thread.
(package private)  void setTarget(java.lang.Runnable target, java.lang.Object lock, boolean notifyAll)
          Assigns a target to this thread, with an optional notify lock and a notify mode.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, 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
 

Field Detail

target

private java.lang.Runnable target

lock

private java.lang.Object lock

doNotifyAll

private boolean doNotifyAll
Constructor Detail

ThreadPool.ThreadPoolThread

public ThreadPool.ThreadPoolThread(int idx,
                                   java.lang.String name)
Creates a ThreadPoolThread object, setting its name according to the given 'idx', daemon type and the priority to the one of the pool.

Parameters:
idx - The index of this thread in the pool
name - The name of the thread
Method Detail

run

public void run()
The method that is run by the thread. This method first joins the idle state in the pool and then enters an infinite loop. In this loop it waits until a target to run exists and runs it. Once the target's run() method is done it re-joins the idle state and notifies the waiting lock object, if one exists.

An interrupt on this thread has no effect other than forcing a check on the target. Normally the target is checked every time the thread is woken up by notify, no interrupts should be done.

Any exception thrown by the target's 'run()' method is catched and this thread is not affected, except for 'ThreadDeath'. If a 'ThreadDeath' exception is catched a warning message is printed by the 'FacilityManager' and the exception is propagated up. For exceptions which are subclasses of 'Error' or 'RuntimeException' the corresponding error condition is set and this thread is not affected. For any other exceptions a new 'RuntimeException' is created and the error condition is set, this thread is not affected.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

setTarget

void setTarget(java.lang.Runnable target,
               java.lang.Object lock,
               boolean notifyAll)
Assigns a target to this thread, with an optional notify lock and a notify mode. The another target is currently running the method will block until it terminates. After setting the new target the runner thread will be wakenup and execytion will start.

Parameters:
target - The runnable object containing the 'run()' method to run.
lock - An object on which notify will be called once the target's run method has finished. A thread to be notified should be waiting on that object. If null no thread is notified.
notifyAll - If true 'notifyAll()', instead of 'notify()', will be called on tghe lock.