All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class w3c.util.ThreadCache

java.lang.Object
   |
   +----w3c.util.ThreadCache

public class ThreadCache
extends Object

Variable Index

 o cachesize
Number of cached threads.
 o freelist
List of free threads.
 o group
The thread group for this thread cache.
 o growasneeded
Should we queue thread requests, rather then creating new threads.
 o idlethreads
Number of idle threads to always maintain alive.
 o idletimeout
The idle timeout, for a thread to wait before being killed.
 o inited
Has this thread cache been initialized ?
 o threadcount
Number of created threads.
 o threadid
Uniq thread identifier within this ThreadCache instance.
 o threadpriority
Cached thread priority.

Constructor Index

 o ThreadCache(String)
Create a thread cache, after creating a new thread group.
 o ThreadCache(ThreadGroup)
Create a thread cache, whose threads are to be children of the group.
 o ThreadCache(ThreadGroup, String)
Create a thread cache, after creating a new thread group.

Method Index

 o allocateThread(boolean)
Allocate a new thread, as requested.
 o getThread(Runnable, boolean)
Request a thread to run on the given object.
 o getThreadGroup()
Get the ThreadGroup managed by this ThreadCache instance.
 o getThreadPriority()
Get the cached thread normal priority.
 o initialize()
Initialize the given thread cache.
 o setCachesize(int)
Set the thread cache size.
 o setCachesize(int, boolean)
Set the thread cache size.
 o setGrowAsNeeded(boolean)
Enable/disable the thread cache to grow as needed.
 o setIdleTimeout(int)
Set the idle timeout.
 o setThreadPriority(int)
Set all the cached threads priority.

Variables

 o inited
 protected boolean inited
Has this thread cache been initialized ?

 o group
 protected ThreadGroup group
The thread group for this thread cache.

 o cachesize
 protected int cachesize
Number of cached threads.

 o threadcount
 protected int threadcount
Number of created threads.

 o threadid
 protected int threadid
Uniq thread identifier within this ThreadCache instance.

 o idlethreads
 protected int idlethreads
Number of idle threads to always maintain alive.

 o growasneeded
 protected boolean growasneeded
Should we queue thread requests, rather then creating new threads.

 o freelist
 protected CachedThread freelist
List of free threads.

 o idletimeout
 protected int idletimeout
The idle timeout, for a thread to wait before being killed. Defaults to 5000 milliseconds.

 o threadpriority
 protected int threadpriority
Cached thread priority.

Constructors

 o ThreadCache
 public ThreadCache(ThreadGroup group)
Create a thread cache, whose threads are to be children of the group.

Parameters:
group - The thread group to which this thread cache is bound.
nstart - Number of thread to create in advance.
 o ThreadCache
 public ThreadCache(String name)
Create a thread cache, after creating a new thread group.

Parameters:
name - The name of the thread group to create.
 o ThreadCache
 public ThreadCache(ThreadGroup parent,
                    String name)
Create a thread cache, after creating a new thread group.

Parameters:
parent - The parent of the thread group to create.
name - The name of the thread group.

Methods

 o allocateThread
 protected synchronized CachedThread allocateThread(boolean waitp)
Allocate a new thread, as requested.

Parameters:
waitp - Should we wait until a thread is available ?
Returns:
A launched CachedThread instance, or null if unable to allocate a new thread, and waitp is false.
 o setCachesize
 public synchronized void setCachesize(int cachesize,
                                       boolean update)
Set the thread cache size. This will also update the number of idle threads to maintain, if requested.

Parameters:
cachesize - The new thread cache size.
update - If true also update the number of threads to maintain idle.
 o setCachesize
 public void setCachesize(int cachesize)
Set the thread cache size. Updaet the number of idle threads to keep alive.

Parameters:
cachesize - The new thread cache size.
 o setGrowAsNeeded
 public void setGrowAsNeeded(boolean onoff)
Enable/disable the thread cache to grow as needed. This flag should be turned on only if always getting a thread as fast as possible is critical.

Parameters:
onoff - The toggle.
 o setThreadPriority
 public void setThreadPriority(int priority)
Set all the cached threads priority. Changing the cached thread priority should be done before the thread cache is initialized, it will not affect already created threads.

Parameters:
priority - The new cachewd threads priority.
 o getThreadPriority
 public int getThreadPriority()
Get the cached thread normal priority.

Returns:
Currently assigned cached thread priority.
 o setIdleTimeout
 public synchronized void setIdleTimeout(int idletimeout)
Set the idle timeout. The idle timeout value is used to eliminate threads that have remain idle for too long (although the thread cache will ensure that a decent minimal number of threads stay around).

Parameters:
idletimeout - The new idle timeout.
 o getThread
 public boolean getThread(Runnable runnable,
                          boolean waitp)
Request a thread to run on the given object.

Parameters:
runnable - The object to run with the allocated thread.
waitp - If true wait until a free thread is available, otherwise, return false.
Returns:
A boolean, true if a thread was successfully allocated for the given object, false otherwise.
 o getThreadGroup
 public ThreadGroup getThreadGroup()
Get the ThreadGroup managed by this ThreadCache instance.

Returns:
A ThreadGroup instance.
 o initialize
 public synchronized void initialize()
Initialize the given thread cache. This two stage initialize method is done so that configuration of the thread cache can be done before any thread get actually created.


All Packages  Class Hierarchy  This Package  Previous  Next  Index