|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.boylesoftware.cb2.util.pool.AdaptiveObjectPool
A general purpose object pool. This implementation allows dynamic growing of the internal storage of idle objects, but it never shrinks.
This implementation is thread-safe and can be used by a number of concurrent threads.
Constructor Summary | |
AdaptiveObjectPool(java.lang.Class objectClass)
Constructs a pool with initial capacity of 10 instances, 0 minimum objects limit and no idle timeout. |
|
AdaptiveObjectPool(java.lang.Class objectClass,
int poolSize,
int minObjects,
long maxIdleTime)
Constructs a pool with the specified intial capacity. |
|
AdaptiveObjectPool(PooledObjectFactory objectFactory)
Constructs a pool with initial capacity of 10 instances, 0 minimum objects limit and no idle timeout. |
|
AdaptiveObjectPool(PooledObjectFactory objectFactory,
int poolSize,
int minObjects,
long maxIdleTime)
Constructs a pool with the specified initial capacity and all other passible parameters. |
Method Summary | |
void |
discard()
Destroys the pool. |
java.lang.Object |
get()
Returns an object from the pool. |
int |
getHitRate()
The hit rate (the relation of the number of new object allocations to the total number of pooled object requests) in 0.01%. |
int |
getNIdles()
Returns the number of idle objects in the pool. |
int |
getNIncrements()
Returns the number of times the pool's internal storage of idle objects had to be increased because it could not hold the required number of idle objects. |
int |
getNUsed()
Returns the number of objects currently being assigned through the get method. |
int |
getPoolSize()
Returns number of idle objects this pool can hold without reallocating the pool's internal storage of idle objects. |
void |
returnObject(java.lang.Object obj)
Returns a borrowed object back to the pool. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public AdaptiveObjectPool(PooledObjectFactory objectFactory, int poolSize, int minObjects, long maxIdleTime)
Note, that if you specify maxIdleTime
parameter, you
should call discrad
method if you want to destroy
the pool, abandoning the reference to the pool used in you application
is not sufficient to free the instance's memory and kill the cleaner
thread.
objectFactory
- the factory to be used for new instances
creation.poolSize
- initial capacity of the pool's internal storage.
The pool can hold this many idle objects without the internal
storage being reallocated, which is a relatively expensive
operation.minObjects
- minimum number of instances the pool should
maintain. This includes both idling and allocated instances.
When the pool initializes it creates this number of instances
and prepopulates itself with them.maxIdleTime
- maximum allowed time in seconds for
instances to be idle. If an instance was not allocated for this
amount of time it is removed from the pool, thus the pool
shrinks. If this parameters is 0
there is no
limit and the pool never shrinks.public AdaptiveObjectPool(PooledObjectFactory objectFactory)
objectFactory
- the factory to be used for new instances
creation.public AdaptiveObjectPool(java.lang.Class objectClass, int poolSize, int minObjects, long maxIdleTime)
objectClass
- class of pooled objects.poolSize
- the maximum number of pooled, idle objects.minObjects
- minimum number of objects in the pool.maxIdleTime
- idle timeout in seconds.public AdaptiveObjectPool(java.lang.Class objectClass)
objectClass
- class of pooled objects.Method Detail |
public java.lang.Object get()
returnObject
method.
public void returnObject(java.lang.Object obj)
obj
- reference to the object to return.
java.lang.IllegalArgumentException
- if obj
parameter is
null
.public void discard()
maxIdleTime
pool parameter
the system creates a special daemon thread, which periodically checks
the pool and shrinks it if needed. The thread is not terminated
automatically after you abandon the pool instance in your application,
because it has an internal reference to the pool instance. Therefore,
if you want to destroy a pool in your application you should
explitiately call this discard
method and then the
instance will be freed and the cleaner thread killed.
There is no need to call this method if you don't use the
maxIdleTime
parameter (that is it is zero).
public int getNIdles()
public int getNUsed()
get
method.
public int getPoolSize()
public int getHitRate()
public int getNIncrements()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |