de.netseeker.ejoe.concurrent
Class ThreadPool

java.lang.Object
  extended by de.netseeker.ejoe.concurrent.ThreadPool
All Implemented Interfaces:
ThreadService, java.lang.Runnable

public class ThreadPool
extends java.lang.Object
implements java.lang.Runnable, ThreadService

Fixed size thread pool implementation for usage with java < 1.5.0

Since:
0.3.0
Author:
netseeker aka Michael Manske

Constructor Summary
ThreadPool()
           
ThreadPool(int numberOfThreads)
           
ThreadPool(int numberOfThreads, int threadPriority)
           
ThreadPool(java.lang.ThreadGroup threadGroup)
           
ThreadPool(java.lang.ThreadGroup threadGroup, int numberOfThreads)
           
 
Method Summary
 int getActiveWorkerCount()
          Returns the count of currently active worker threads
 java.lang.Thread[] getAllWorkers()
           
 int getCurrentPoolsize()
          Returns the real pool size which is the count of all living worker threads in the pool
 int getExpectedPoolsize()
          Returns the expected pool size, which might differ from the real pool size because workers died caused by unexpected exceptions etc.
 int getRunnableCount()
          Returns number of runnable object in the queue.
 void invokeLater(java.lang.Runnable task)
          Dispatch a new task onto this pool to be invoked asynchronously later
 void resize(int poolSize)
          Resizes the pool to the new size
 void run()
          The method ran by the pool of background threads
 void stop()
          Signals this pool not to request and run workers from the queue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreadPool

public ThreadPool(int numberOfThreads,
                  int threadPriority)
Parameters:
numberOfThreads -
threadPriority -

ThreadPool

public ThreadPool(int numberOfThreads)
Parameters:
numberOfThreads -

ThreadPool

public ThreadPool()

ThreadPool

public ThreadPool(java.lang.ThreadGroup threadGroup)
Parameters:
threadGroup -

ThreadPool

public ThreadPool(java.lang.ThreadGroup threadGroup,
                  int numberOfThreads)
Parameters:
threadGroup -
numberOfThreads -
Method Detail

stop

public void stop()
Signals this pool not to request and run workers from the queue

Specified by:
stop in interface ThreadService

getRunnableCount

public int getRunnableCount()
Returns number of runnable object in the queue.


invokeLater

public void invokeLater(java.lang.Runnable task)
Dispatch a new task onto this pool to be invoked asynchronously later

Specified by:
invokeLater in interface ThreadService
Parameters:
task - a task to execute within one of the available worker threads

getAllWorkers

public java.lang.Thread[] getAllWorkers()
Returns:

getActiveWorkerCount

public int getActiveWorkerCount()
Returns the count of currently active worker threads

Specified by:
getActiveWorkerCount in interface ThreadService
Returns:
the count of currently active worker threads

getExpectedPoolsize

public int getExpectedPoolsize()
Returns the expected pool size, which might differ from the real pool size because workers died caused by unexpected exceptions etc.

Specified by:
getExpectedPoolsize in interface ThreadService
Returns:
the expected pool size

getCurrentPoolsize

public int getCurrentPoolsize()
Returns the real pool size which is the count of all living worker threads in the pool

Specified by:
getCurrentPoolsize in interface ThreadService
Returns:
the real pool size

resize

public void resize(int poolSize)
Resizes the pool to the new size

Specified by:
resize in interface ThreadService
Parameters:
numberOfThreads - the new pool size

run

public void run()
The method ran by the pool of background threads

Specified by:
run in interface java.lang.Runnable


Copyright © 2005-2007 netseeker. All Rights Reserved.