KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > ejb > containers > util > pool > BoundedPool


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /**
25  * <BR> <I>$Source: /cvs/glassfish/appserv-core/src/java/com/sun/ejb/containers/util/pool/BoundedPool.java,v $</I>
26  * @author $Author: tcfujii $
27  * @version $Revision: 1.3 $ $Date: 2005/12/25 04:13:35 $
28  */

29  
30
31 package com.sun.ejb.containers.util.pool;
32
33 import java.util.Collection JavaDoc;
34 import java.util.ArrayList JavaDoc;
35 import java.util.logging.*;
36
37 import com.sun.logging.*;
38
39 /**
40  * <p>Abstract pool provides the basic implementation of an object pool.
41  * The implementation uses a linked list to maintain a list of (available)
42  * objects. If the pool is empty it simply creates one using the
43  * ObjectFactory instance. Subclasses can change this behaviour by overriding
44  * getObject(...) and returnObject(....) methods. This class provides basic
45  * support for synchronization, event notification, pool shutdown and pool
46  * object recycling. It also does some very basic bookkeeping like the
47  * number of objects created, number of threads waiting for object.
48  * <p> Subclasses can make use of these book-keeping data to provide complex
49  * pooling mechanism like LRU / MRU / Random. Also, note that AbstractPool
50  * does not have a notion of pool limit. It is upto to the derived classes
51  * to implement these features.
52  *
53  */

54 public class BoundedPool
55     extends AbstractPool
56 {
57     
58     private static Logger _logger;
59     static{
60         _logger=LogDomains.getLogger(LogDomains.EJB_LOGGER);
61     }
62     
63     protected int previousSize = 0;
64     
65     public BoundedPool(ObjectFactory factory, int steadyPoolSize,
66         int resizeQuantity, int maxPoolsize, long maxWaitTimeInMillis,
67         int idleTimeoutInSeconds, ClassLoader JavaDoc loader)
68     {
69         super(factory, steadyPoolSize, resizeQuantity, maxPoolsize,
70               maxWaitTimeInMillis, idleTimeoutInSeconds, loader);
71         super.poolName="BoundedPool";
72     }
73     
74     protected void removeIdleObjects() {
75         int curSize = 0;
76         int count = 0;
77         synchronized (list) {
78             curSize = list.size();
79         }
80
81         if(curSize <= steadyPoolSize)
82             return; // no need to trim the pool beyond steadyPoolSize
83
count = (curSize > (steadyPoolSize + resizeQuantity) ) ?
84             resizeQuantity: (curSize - steadyPoolSize);
85         previousSize = curSize;
86         
87         if (count > 0) {
88             _logger.log(Level.FINE,
89                         "BoundedPool removing " + count + " objects");
90             super.remove(count);
91         }
92     }
93
94 }
95
Popular Tags