All Packages Class Hierarchy This Package Previous Next Index
Class w3c.util.ThreadCache
java.lang.Object
|
+----w3c.util.ThreadCache
- public class ThreadCache
- extends Object
-
cachesize
- Number of cached threads.
-
freelist
- List of free threads.
-
group
- The thread group for this thread cache.
-
growasneeded
- Should we queue thread requests, rather then creating new threads.
-
idlethreads
- Number of idle threads to always maintain alive.
-
idletimeout
- The idle timeout, for a thread to wait before being killed.
-
inited
- Has this thread cache been initialized ?
-
threadcount
- Number of created threads.
-
threadid
- Uniq thread identifier within this ThreadCache instance.
-
threadpriority
- Cached thread priority.
-
ThreadCache(String)
- Create a thread cache, after creating a new thread group.
-
ThreadCache(ThreadGroup)
- Create a thread cache, whose threads are to be children of the group.
-
ThreadCache(ThreadGroup, String)
- Create a thread cache, after creating a new thread group.
-
allocateThread(boolean)
- Allocate a new thread, as requested.
-
getThread(Runnable, boolean)
- Request a thread to run on the given object.
-
getThreadGroup()
- Get the ThreadGroup managed by this ThreadCache instance.
-
getThreadPriority()
- Get the cached thread normal priority.
-
initialize()
- Initialize the given thread cache.
-
setCachesize(int)
- Set the thread cache size.
-
setCachesize(int, boolean)
- Set the thread cache size.
-
setGrowAsNeeded(boolean)
- Enable/disable the thread cache to grow as needed.
-
setIdleTimeout(int)
- Set the idle timeout.
-
setThreadPriority(int)
- Set all the cached threads priority.
inited
protected boolean inited
- Has this thread cache been initialized ?
group
protected ThreadGroup group
- The thread group for this thread cache.
cachesize
protected int cachesize
- Number of cached threads.
threadcount
protected int threadcount
- Number of created threads.
threadid
protected int threadid
- Uniq thread identifier within this ThreadCache instance.
idlethreads
protected int idlethreads
- Number of idle threads to always maintain alive.
growasneeded
protected boolean growasneeded
- Should we queue thread requests, rather then creating new threads.
freelist
protected CachedThread freelist
- List of free threads.
idletimeout
protected int idletimeout
- The idle timeout, for a thread to wait before being killed.
Defaults to 5000 milliseconds.
threadpriority
protected int threadpriority
- Cached thread priority.
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.
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.
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.
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.
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.
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.
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.
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.
getThreadPriority
public int getThreadPriority()
- Get the cached thread normal priority.
- Returns:
- Currently assigned cached thread priority.
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.
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.
getThreadGroup
public ThreadGroup getThreadGroup()
- Get the ThreadGroup managed by this ThreadCache instance.
- Returns:
- A ThreadGroup instance.
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