public final class

Pool

extends Object
java.lang.Object
   ↳ com.sun.jndi.ldap.pool.Pool

Class Overview

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.

Summary

Public Constructors
Pool(int initSize, int prefSize, int maxSize)
Public Methods
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()
Returns a string representation of the object.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public Pool (int initSize, int prefSize, int maxSize)

Public Methods

public void expire (long threshold)

Goes through the connections in this Pool and expires ones that have been idle before 'threshold'. An expired connection is closed and then removed from the pool (removePooledConnection() will eventually be called, and the list of pools itself removed if it becomes empty).

Parameters
threshold connections idle before 'threshold' should be closed and removed.

public PooledConnection getPooledConnection (Object id, long timeout, PooledConnectionFactory factory)

Gets a pooled connection for id. The pooled connection might be newly created, as governed by the maxSize and prefSize settings. If a pooled connection is unavailable and cannot be created due to the maxSize constraint, this call blocks until the constraint is removed or until 'timeout' ms has elapsed.

Parameters
id identity of the connection to get
timeout the number of milliseconds to wait before giving up
factory the factory to use for creating the connection if creation is necessary
Returns
  • a pooled connection
Throws
NamingException the connection could not be created due to an error.

public void showStats (PrintStream out)

public String toString ()

Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

Returns
  • a string representation of the object.