sjt.mgmt
Class ThreadArray

java.lang.Object
  |
  +--sjt.mgmt.ThreadArray
All Implemented Interfaces:
ThreadingGroup

public class ThreadArray
extends java.lang.Object
implements ThreadingGroup

An implementation of ThreadingGroup interface. In this case, the implementation is based on a simple thread array []. The ThreadArray is under strict control of the ThreadManager class, which adds, removes and uses threads accordingly.

Since:
SJT 0.1

Constructor Summary
ThreadArray(java.lang.String name, int size)
           
 
Method Summary
 void addThread(java.lang.Thread thread)
          Add thread to the wrapped collection.
 void destroy()
          Destroy can be called by the user code in order to prompt joining and cleanup of all working threads.
 boolean isEmpty()
          Check whether work has one or more work items in collection.
 java.lang.Thread removeThread()
          Remove one thread from the wrapped collection.
 int size()
          Check how many items in work collection.
 java.lang.Thread useThread()
          Similiar to removeThread but the thread reference is maintained in Group.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreadArray

public ThreadArray(java.lang.String name,
                   int size)
Method Detail

addThread

public void addThread(java.lang.Thread thread)
Add thread to the wrapped collection. Threads are added by ThreadManager only.
Specified by:
addThread in interface ThreadingGroup
Parameters:
thread - One working thread.

removeThread

public java.lang.Thread removeThread()
Remove one thread from the wrapped collection. The collection itself will decide which thread is returned. FIFO, LIFO, and any other necessary ordering. Thread should be added back into the collection by the ThreadManager.
Specified by:
removeThread in interface ThreadingGroup
Returns:
thread A working thread.

useThread

public java.lang.Thread useThread()
Similiar to removeThread but the thread reference is maintained in Group.
Specified by:
useThread in interface ThreadingGroup
Returns:
thread A working thread.

size

public int size()
Check how many items in work collection.
Specified by:
size in interface ThreadingGroup
Returns:
size of work collection.

isEmpty

public boolean isEmpty()
Check whether work has one or more work items in collection.
Specified by:
isEmpty in interface ThreadingGroup
Returns:
true or false if collection empty.

destroy

public void destroy()
Destroy can be called by the user code in order to prompt joining and cleanup of all working threads. Destroy is also called by the finalize method, during garbage collection, if the user code does not call it explicitly.
Specified by:
destroy in interface ThreadingGroup