gr.demokritos.iit.jinsect.threading
Class ThreadQueue

java.lang.Object
  extended by gr.demokritos.iit.jinsect.threading.ThreadQueue
Direct Known Subclasses:
ThreadList

public class ThreadQueue
extends java.lang.Object

A queue of threads for parallel execution. Should probably be replaced by ThreadPoolExecutor.


Field Summary
protected  int Max
          The maximum number of running threads.
protected  java.util.Queue qThreads
          The queue of threads.
 
Constructor Summary
ThreadQueue()
          Initializes a thread queue, with the default maximum number of threads running at the same time.
ThreadQueue(int iMax)
          Initializes a thread queue, with a given maximum of threads running at the same time.
 
Method Summary
 boolean addThreadFor(java.lang.Runnable r)
          Adds a Runnable object in the queue for execution, if possible.
 void waitUntilCompletion()
          Waits until all running threads have been complete.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

qThreads

protected java.util.Queue qThreads
The queue of threads.


Max

protected int Max
The maximum number of running threads.

Constructor Detail

ThreadQueue

public ThreadQueue()
Initializes a thread queue, with the default maximum number of threads running at the same time.


ThreadQueue

public ThreadQueue(int iMax)
Initializes a thread queue, with a given maximum of threads running at the same time.

Parameters:
iMax - The maximum number of threads running at the same time.
Method Detail

addThreadFor

public boolean addThreadFor(java.lang.Runnable r)
Adds a Runnable object in the queue for execution, if possible. First-in, first-out logic is followed.

Parameters:
r - The runnable object to execute.
Returns:
True if the object was queued for execution, or false if the queue was full.

waitUntilCompletion

public void waitUntilCompletion()
                         throws java.lang.InterruptedException
Waits until all running threads have been complete.

Throws:
java.lang.InterruptedException