|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--jason.service.pool.ThreadPool
This class is an generic implementation of a thread pool, which takes the following input
a) Size of the pool to be constructed
b) Name of the class which implements Runnable (which has a visible default constructor)
and constructs a thread pool with active threads that are waiting for activation.
once the threads have finished processing they come back and wait once again in the pool.
This thread pool engine can be locked i.e. if some internal operation is performed on the pool
then it is preferable that the thread engine be locked. Locking ensures that no new threads are issued
by the engine. However, the currently executing threads are allowed to continue till they come back
to the passivePool.
Author - Sanjay "Ironluca" Debnath Ironluca@yahoo.com
Last Modified - 9/03/2001
Field Summary | |
protected ActivePoolInt |
activePool
The pool where the currently active threads which are servicing the clients are kept. |
protected int |
activePoolSize
Current no of threads in the pool which are not available for servicing. |
protected PassivePoolInt |
passivePool
The pool where the currently passive threads which are not servicing the clients are kept. |
protected int |
passivePoolSize
Current no of threads in the pool which are available for servicing. |
protected boolean |
poolLocked
This represents the status of the pool - unlocked or locked. |
protected ThreadCapsuleInt |
tempThreadCapsule
Temporary storage for ThreadCapsule objects. |
protected java.lang.Class |
threadClass
The class for which the pool is constructed, it must implement runnable and have a visible default constructor. |
protected int |
totalPoolSize
Initial size of the pool as indicated by the user. |
Constructor Summary | |
ThreadPool(java.lang.Class threadClass,
int totalPoolSize)
The only visible constructor for the class. |
Method Summary | |
int |
getActivePoolSize()
Returns the value of the activePoolSize variable. |
int |
getPassivePoolSize()
Returns the value of the passivePoolSize variable. |
ThreadCapsuleInt |
getThreadCapsule()
This method returns a ThreadCapsule object with the client processing thread embedded in it.
|
java.lang.Class |
getThreadClass()
Returns the class for which the pool is being maintained. |
int |
getTotalPoolSize()
Returns the value of totalPoolSize variable. |
protected void |
initializePools(java.lang.Class threadClass,
int totalPoolSize)
This method is called by the constructor as well as setThreadClass
method to initialize or reinitialize all the pools (ActivePool as well as
PassivePool ). |
boolean |
isPoolLocked()
Returns the current value of the poolLocked variable |
void |
setPoolLocked(boolean lockingState)
Toggles the locked or unlocked state of the pool |
void |
setThreadClass(java.lang.Class threadClass,
int totalPoolSize)
Destroyes the current pools ( ActivePool as well as PassivePool )
and reinitializes the pool. |
void |
setTotalPoolSize(int totalPoolSize)
This method sets the size of the total pool (active + passive) pool - if the size of the active pool is more than the size of the passive pool then ClientUnderServiceException
is thrown otherwise the size of the passive pool is reduced to (totalPoolSize-newPoolSize). |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected int totalPoolSize
protected int activePoolSize
protected int passivePoolSize
protected java.lang.Class threadClass
protected ActivePoolInt activePool
protected PassivePoolInt passivePool
protected boolean poolLocked
protected ThreadCapsuleInt tempThreadCapsule
Constructor Detail |
public ThreadPool(java.lang.Class threadClass, int totalPoolSize) throws IllegalClassException, java.lang.IllegalAccessException, java.lang.InstantiationException
IllegalClassException
- This exception is generated if the class supplied for pooling does not
implement java.lang.Runnable in any form (either explicitely or by extending Thread).
java.lang.IllegalAccessException
java.lang.InstantiationException
Method Detail |
protected void initializePools(java.lang.Class threadClass, int totalPoolSize) throws IllegalClassException, java.lang.IllegalAccessException, java.lang.InstantiationException
constructor
as well as setThreadClass
method to initialize or reinitialize all the pools (ActivePool
as well as
PassivePool
).
IllegalClassException
java.lang.IllegalAccessException
java.lang.InstantiationException
public java.lang.Class getThreadClass()
getThreadClass
in interface ThreadPoolInt
public void setThreadClass(java.lang.Class threadClass, int totalPoolSize) throws IllegalClassException, java.lang.IllegalAccessException, java.lang.InstantiationException
ActivePool
as well as PassivePool
)
and reinitializes the pool. This method should not be called if there are current clients being serviced.initializePools
method is called with the requisit parameters
which reinitializes the ActivePool as well as the PassivePool. Thus effectively destroying the earlier pools.
setThreadClass
in interface ThreadPoolInt
IllegalClassException
- This exception is thrown if the Class supplied does not implement
java.lang.Runnable either directly or indirectly by extending java.lang.Thread.
java.lang.IllegalAccessException
java.lang.InstantiationException
public int getTotalPoolSize()
getTotalPoolSize
in interface ThreadPoolInt
public void setTotalPoolSize(int totalPoolSize) throws ClientsUnderServiceException, IllegalClassException, java.lang.IllegalAccessException, java.lang.InstantiationException
ClientUnderServiceException
is thrown otherwise the size of the passive pool is reduced to (totalPoolSize-newPoolSize).PassivePool
). In case, the target size of the pool is less than the current
number of thread objects in the PassivePool
, some thread objects are taken out of the ActivePool. However,
it is not possible to determine which thread objects have been taken out. This method may have detremental
effect on threads that are right now running. However, since a thread is not garbage collected while it is
still active, the servicing of the client/request should proceed without interruption. After the thread finishes
execution, it shall be garbage collected.
setTotalPoolSize
in interface ThreadPoolInt
ClientsUnderServiceException
IllegalClassException
java.lang.IllegalAccessException
java.lang.InstantiationException
public int getActivePoolSize()
getActivePoolSize
in interface ThreadPoolInt
activePool
.public int getPassivePoolSize()
getPassivePoolSize
in interface ThreadPoolInt
passivePool
.public boolean isPoolLocked()
poolLocked
variable
isPoolLocked
in interface ThreadPoolInt
public void setPoolLocked(boolean lockingState)
setPoolLocked
in interface ThreadPoolInt
public ThreadCapsuleInt getThreadCapsule()
ThreadCapsule
object with the client processing thread embedded in it.
This object is responsible for controlling the core thread, if there are no passive threads in the pool
this method returns null.
getThreadCapsule
in interface ThreadPoolInt
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |