com.msi.threadpuddle
Class ThreadPuddleImpl

java.lang.Object
  |
  +--com.msi.threadpuddle.ThreadPuddleImpl
All Implemented Interfaces:
ThreadPuddle

public class ThreadPuddleImpl
extends java.lang.Object
implements ThreadPuddle


Field Summary
private  boolean debug
           
private  java.util.Vector pendingJobs
           
private  int threadCount
           
private  java.util.Vector threads
           
 
Constructor Summary
ThreadPuddleImpl(java.util.Properties props)
          ThreadPuddleImpl - create a new ThreadPuddleImpl initializing state from the supplied properties.
 
Method Summary
 void addJob(java.lang.Runnable job)
          addJob put a new job into the work queue and notify the next available thread.
 int findMe()
          findMe called by a pool thread to find itself in the vector of available threads.
private  int firstIdleThread()
          firstIdleThread - Called by the thread pool to find the first idle thread.
 java.lang.Runnable getJob()
          getJob retrieve the next available job.
 State getState()
          getState return the current snapshot of the puddle state.
 void idleMe()
          idleMe mark the current thread as idle.
private  int idleThreads()
           
 int jobCount()
           
 void removeMe()
          removeMe called by a pool thread to remove itself from the vector of available threads
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

threadCount

private int threadCount

pendingJobs

private java.util.Vector pendingJobs

threads

private java.util.Vector threads

debug

private boolean debug
Constructor Detail

ThreadPuddleImpl

public ThreadPuddleImpl(java.util.Properties props)
                 throws java.lang.NumberFormatException,
                        java.lang.IllegalArgumentException
ThreadPuddleImpl - create a new ThreadPuddleImpl initializing state from the supplied properties.

Method Detail

jobCount

public int jobCount()

addJob

public void addJob(java.lang.Runnable job)
addJob put a new job into the work queue and notify the next available thread.

If all threads are busy the job remains in queue until one of the busy threads completes when it will check the work queue and process this job.

Specified by:
addJob in interface ThreadPuddle

getState

public State getState()
getState return the current snapshot of the puddle state.

Specified by:
getState in interface ThreadPuddle
Returns:
State puddle status object.

idleThreads

private int idleThreads()

firstIdleThread

private int firstIdleThread()
firstIdleThread - Called by the thread pool to find the first idle thread.

Returns:
int index of the next available thread.

findMe

public int findMe()
findMe called by a pool thread to find itself in the vector of available threads.

Returns:
the index of the current (my) thread.

idleMe

public void idleMe()
idleMe mark the current thread as idle.


getJob

public java.lang.Runnable getJob()
getJob retrieve the next available job. This is the job with the longest time in queue.

Returns:
Runnable job from the tail of the queue, null if job queue is empty.

removeMe

public void removeMe()
removeMe called by a pool thread to remove itself from the vector of available threads



Copyright © 2001-2002 MileStone Solutions, Inc. All Rights Reserved.