|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sun.jndi.ldap.pool.Pool
public final class Pool
A map of pool ids to Connections. Key is an object that uniquely identifies a PooledConnection request (typically information needed to create the connection). The definitions of the key's equals() and hashCode() methods are vital to its unique identification in a Pool. Value is a ConnectionsRef, which is a reference to Connections, a list of equivalent connections. Supports methods that - retrieves (or creates as necessary) a connection from the pool - removes expired connections from the pool Connections cleanup: A WeakHashMap is used for mapping the pool ids and Connections. A SoftReference from the value to the key is kept to hold the map entry as long as possible. This allows the GC to remove Connections from the Pool under situations of VM running out of resources. To take an appropriate action of 'closing the connections' before the GC reclaims the ConnectionsRef objects, the ConnectionsRef objects are made weakly reachable through a list of weak references registered with a reference queue. Upon an entry gets removed from the WeakHashMap, the ConnectionsRef (value in the map) object is weakly reachable. When another sweep of clearing the weak references is made by the GC it puts the corresponding ConnectionsWeakRef object into the reference queue. The reference queue is monitored lazily for reclaimable Connections whenever a pooled connection is requested or a call to remove the expired connections is made. The monitoring is done regularly when idle connection timeout is set as the PoolCleaner removes expired connections periodically. As determined by the experiements, cleanup of resources using the ReferenceQueue mechanism is reliable and has immidiate effect than the finalizer approach.
| Constructor Summary | |
|---|---|
Pool(int initSize,
int prefSize,
int maxSize)
|
|
| Method Summary | |
|---|---|
void |
expire(long threshold)
Goes through the connections in this Pool and expires ones that have been idle before 'threshold'. |
PooledConnection |
getPooledConnection(Object id,
long timeout,
PooledConnectionFactory factory)
Gets a pooled connection for id. |
void |
showStats(PrintStream out)
|
String |
toString()
toString creates a printable string that represents this object for debugging purposes. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Pool(int initSize,
int prefSize,
int maxSize)
| Method Detail |
|---|
public PooledConnection getPooledConnection(Object id,
long timeout,
PooledConnectionFactory factory)
throws NamingException
id - identity of the connection to gettimeout - the number of milliseconds to wait before giving upfactory - the factory to use for creating the connection if
creation is necessary
NamingException - the connection could not be created due to
an error.public void expire(long threshold)
threshold - connections idle before 'threshold' should be closed
and removed.public void showStats(PrintStream out)
public String toString()
ObjectThe default implementation returns getClass().getName() + '@' + Integer.toHexString(hashCode()).
toString in class Object
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||