Acme
Class Utils.ThreadPool

java.lang.Object
  extended by Acme.Utils.ThreadPool
Enclosing class:
Utils

public static final class Utils.ThreadPool
extends Object


Field Summary
protected  HashMap busyThreads
           
protected static int counter
           
protected  ArrayList freeThreads
           
static String MAXNOTHREAD
           
protected  int maxThreads
           
protected  Utils.ThreadFactory threadFactory
           
 
Constructor Summary
Utils.ThreadPool(Properties properties, Utils.ThreadFactory threadfactory)
          Creates a thread pool not queued with max number of threads defined in properties or DEF_MAX_POOLED_THREAD = 20
 
Method Summary
 void executeThread(Runnable runnable)
          Takes a new task for execution by a threads in pool will wait until free threads if number of threads reached max
protected  void finalize()
           
 int getMaxThreads()
          Returns setting for max number of threads
 void setMaxThreads(int newSize)
          Assigns a new value for max threads
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAXNOTHREAD

public static final String MAXNOTHREAD
See Also:
Constant Field Values

counter

protected static int counter

freeThreads

protected ArrayList freeThreads

busyThreads

protected HashMap busyThreads

maxThreads

protected int maxThreads

threadFactory

protected Utils.ThreadFactory threadFactory
Constructor Detail

Utils.ThreadPool

public Utils.ThreadPool(Properties properties,
                        Utils.ThreadFactory threadfactory)
Creates a thread pool not queued with max number of threads defined in properties or DEF_MAX_POOLED_THREAD = 20

Parameters:
Properties - where property THREADSINPOOL gives max threads Note if THREADSINPOOL not integers, or negative then DEF_MAX_POOLED_THREAD used
Method Detail

setMaxThreads

public void setMaxThreads(int newSize)
Assigns a new value for max threads

Parameters:
int - new value of max threads, can't be less than 2, but can be 0 If current number threads exceed the value, then extra thread will be discarded gracefully

getMaxThreads

public int getMaxThreads()
Returns setting for max number of threads

Returns:
int setting for max number of threads, doesn't reflect actual number of threads though

executeThread

public void executeThread(Runnable runnable)
Takes a new task for execution by a threads in pool will wait until free threads if number of threads reached max

Parameters:
Runnable - task for execution

finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2011. All Rights Reserved.