Return-Path: Delivered-To: apmail-tomcat-dev-archive@www.apache.org Received: (qmail 9711 invoked from network); 2 Jul 2009 17:09:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 2 Jul 2009 17:09:04 -0000 Received: (qmail 75541 invoked by uid 500); 2 Jul 2009 17:09:13 -0000 Delivered-To: apmail-tomcat-dev-archive@tomcat.apache.org Received: (qmail 75457 invoked by uid 500); 2 Jul 2009 17:09:13 -0000 Mailing-List: contact dev-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Developers List" Delivered-To: mailing list dev@tomcat.apache.org Received: (qmail 75446 invoked by uid 99); 2 Jul 2009 17:09:13 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Jul 2009 17:09:13 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Jul 2009 17:09:10 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 82C582388902; Thu, 2 Jul 2009 17:08:50 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r790684 - /tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java Date: Thu, 02 Jul 2009 17:08:50 -0000 To: dev@tomcat.apache.org From: fhanik@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090702170850.82C582388902@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: fhanik Date: Thu Jul 2 17:08:50 2009 New Revision: 790684 URL: http://svn.apache.org/viewvc?rev=790684&view=rev Log: Add some doco, make shared variables volatile Modified: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java Modified: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java?rev=790684&r1=790683&r2=790684&view=diff ============================================================================== --- tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java (original) +++ tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java Thu Jul 2 17:08:50 2009 @@ -48,17 +48,28 @@ */ public class ConnectionPool { + /** + * Prefix type for JMX registration + */ public static final String POOL_JMX_TYPE_PREFIX = "tomcat.jdbc:type="; - //logger + /** + * Logger + */ protected static Log log = LogFactory.getLog(ConnectionPool.class); //=============================================================================== // INSTANCE/QUICK ACCESS VARIABLE //=============================================================================== + /** + * Carries the size of the pool, instead of relying on a queue implementation + * that usually iterates over to get an exact count + */ private AtomicInteger size = new AtomicInteger(0); + /** * All the information about the connection pool + * These are the properties the pool got instantiated with */ private PoolProperties poolProperties; @@ -76,12 +87,12 @@ /** * The thread that is responsible for checking abandoned and idle threads */ - private PoolCleaner poolCleaner; + private volatile PoolCleaner poolCleaner; /** * Pool closed flag */ - private boolean closed = false; + private volatile boolean closed = false; /** * Since newProxyInstance performs the same operation, over and over @@ -95,7 +106,7 @@ private ThreadPoolExecutor cancellator = new ThreadPoolExecutor(0,1,1000,TimeUnit.MILLISECONDS,new LinkedBlockingQueue()); /** - * reference to mbean + * reference to the JMX mbean */ protected org.apache.tomcat.jdbc.pool.jmx.ConnectionPool jmxPool = null; @@ -119,6 +130,14 @@ } + /** + * Retrieves a Connection future. If a connection is not available, one can block using future.get() + * until a connection has become available. + * If a connection is not retrieved, the Future must be cancelled in order for the connection to be returned + * to the pool. + * @return + * @throws SQLException + */ public Future getConnectionAsync() throws SQLException { if (idle instanceof FairBlockingQueue) { Future pcf = ((FairBlockingQueue)idle).pollAsync(); @@ -130,7 +149,7 @@ /** * Borrows a connection from the pool - * @return Connection - a java.sql.Connection reflection proxy, wrapping the underlying object. + * @return Connection - a java.sql.Connection/javax.sql.PooledConnection reflection proxy, wrapping the underlying object. * @throws SQLException */ public Connection getConnection() throws SQLException { @@ -180,6 +199,10 @@ return busy.size(); } + /** + * Returns the number of idle connections + * @return + */ public int getIdle() { return idle.size(); } @@ -197,7 +220,11 @@ //=============================================================================== + /** + * configures a pooled connection as a proxy + */ protected Connection setupConnection(PooledConnection con) throws SQLException { + //fetch previous interceptor proxy JdbcInterceptor handler = con.getHandler(); if (handler==null) { //build the proxy handler @@ -252,6 +279,10 @@ return proxyClassConstructor; } + /** + * If the connection pool gets garbage collected, lets make sure we clean up + * and close all the connections + */ @Override protected void finalize() throws Throwable { close(true); --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org For additional commands, e-mail: dev-help@tomcat.apache.org