Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.scopemvc.util
Class BasicObjectPool  view BasicObjectPool download BasicObjectPool.java

java.lang.Object
  extended byorg.scopemvc.util.BasicObjectPool
All Implemented Interfaces:
ObjectPool

public class BasicObjectPool
extends java.lang.Object
implements ObjectPool

Pools objects given a factory and optional maximum pool size.

Version:
$Revision: 1.3 $

Field Summary
private  PoolableObjectFactory factory
          The factory used to create pooled objects
private  java.util.LinkedList freeList
          Queue of free instances
private  java.lang.Object lock
          Used for synchronisation
private static org.apache.commons.logging.Log LOG
           
private  int maxSize
          The maximum number of objects to pool
 
Constructor Summary
BasicObjectPool(PoolableObjectFactory inFactory)
          Construct a basic object pool with the specified factory and a maximum pool size of Integer.MAX_VALUE.
BasicObjectPool(PoolableObjectFactory inFactory, int inMaxSize)
          Construct a basic object pool with the specified factory and maximum pool size.
 
Method Summary
 java.lang.Object borrowObject()
          Obtains an instance of the pooled class.
 java.lang.Object borrowObjectIfExists()
          Obtains an instance of the pooled class.
 void returnObject(java.lang.Object object)
          Returns an instance to the pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

private static final org.apache.commons.logging.Log LOG

lock

private final java.lang.Object lock
Used for synchronisation


freeList

private final java.util.LinkedList freeList
Queue of free instances


factory

private final PoolableObjectFactory factory
The factory used to create pooled objects


maxSize

private final int maxSize
The maximum number of objects to pool

Constructor Detail

BasicObjectPool

public BasicObjectPool(PoolableObjectFactory inFactory)
Construct a basic object pool with the specified factory and a maximum pool size of Integer.MAX_VALUE.


BasicObjectPool

public BasicObjectPool(PoolableObjectFactory inFactory,
                       int inMaxSize)
Construct a basic object pool with the specified factory and maximum pool size.

Method Detail

borrowObject

public java.lang.Object borrowObject()
Obtains an instance of the pooled class. Blocks if no free instances.

Specified by:
borrowObject in interface ObjectPool

borrowObjectIfExists

public java.lang.Object borrowObjectIfExists()
Obtains an instance of the pooled class. Returns null if no free instances.

Specified by:
borrowObjectIfExists in interface ObjectPool

returnObject

public void returnObject(java.lang.Object object)
Returns an instance to the pool.

Specified by:
returnObject in interface ObjectPool