You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by fh...@apache.org on 2009/01/31 00:32:39 UTC

svn commit: r739449 - in /tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool: ConnectionPool.java DataSourceFactory.java interceptor/mbeans-descriptors.xml

Author: fhanik
Date: Fri Jan 30 23:32:38 2009
New Revision: 739449

URL: http://svn.apache.org/viewvc?rev=739449&view=rev
Log:
fix sizing issue when db is restarted
fix JMX domain name
fix exception handling

Modified:
    tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
    tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java
    tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/mbeans-descriptors.xml

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=739449&r1=739448&r2=739449&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 Fri Jan 30 23:32:38 2009
@@ -48,7 +48,7 @@
  */
 
 public class ConnectionPool {
-    public static final String POOL_JMX_TYPE_PREFIX = "org.apache.tomcat.jdbc.pool.jmx:type=";
+    public static final String POOL_JMX_TYPE_PREFIX = "tomcat.jdbc:type=";
     
     //logger
     protected static Log log = LogFactory.getLog(ConnectionPool.class);
@@ -84,11 +84,6 @@
     protected boolean closed = false;
 
     /**
-     * Size of the pool
-     */
-    protected AtomicInteger size = new AtomicInteger(0);
-
-    /**
      * Since newProxyInstance performs the same operation, over and over
      * again, it is much more optimized if we simply store the constructor ourselves.
      */
@@ -285,7 +280,6 @@
             }
             if (pool.size()==0 && force && pool!=busy) pool = busy;
         }
-        size.set(0);
         if (this.getPoolProperties().isJmxEnabled()) stopJmx();
         PoolProperties.InterceptorDefinition[] proxies = getPoolProperties().getJdbcInterceptorsAsArray();
         for (int i=0; i<proxies.length; i++) {
@@ -445,14 +439,16 @@
             if (con!=null) {
                 PooledConnection result = borrowConnection(now, con);
                 //validation might have failed, in which case null is returned
+                //should not happen anymore
                 if (result!=null) return result;
             }
-            if (size.get() < getPoolProperties().getMaxActive()) {
-                if (size.addAndGet(1) <= getPoolProperties().getMaxActive()) {
-                    return createConnection(now, con);
-                } else {
-                    size.addAndGet(-1); //restore the value, we didn't create a connection
-                }
+            
+            //if we get here, see if we need to create one
+            //this is not 100% accurate since it doesn't use a shared
+            //atomic variable - a connection can become idle while we are creating 
+            //a new connection
+            if (busy.size() < getPoolProperties().getMaxActive()) {
+                return createConnection(now, con);
             } //end if
 
             //calculate wait time for this iteration
@@ -609,9 +605,9 @@
                             con.validate(PooledConnection.VALIDATE_RETURN)) {
                         con.setStackTrace(null);
                         con.setTimestamp(System.currentTimeMillis());
-                        if (!idle.offer(con)) {
+                        if ((idle.size()>=poolProperties.getMaxIdle()) || (!idle.offer(con))) {
                             if (log.isDebugEnabled()) {
-                                log.debug("Connection ["+con+"] will be closed and not returned to the pool, idle.offer failed.");
+                                log.debug("Connection ["+con+"] will be closed and not returned to the pool, idle["+idle.size()+"]>=maxIdle["+poolProperties.getMaxIdle()+"] idle.offer failed.");
                             }
                             release(con);
                         }
@@ -757,7 +753,7 @@
     }
 
     protected void finalize(PooledConnection con) {
-        size.addAndGet(-1);
+        
     }
 
     protected void startJmx() {

Modified: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java?rev=739449&r1=739448&r2=739449&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java (original)
+++ tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java Fri Jan 30 23:32:38 2009
@@ -19,6 +19,7 @@
 
 import java.io.ByteArrayInputStream;
 import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.sql.Connection;
@@ -439,7 +440,11 @@
                 m = datasource.getClass().getMethod(method.getName(), method.getParameterTypes());
                 methods.put(method, m);
             }
-            return m.invoke(datasource, args);
+            try {
+                return m.invoke(datasource, args);
+            }catch (InvocationTargetException t) {
+                throw t.getTargetException();
+            }
         }
 
     }

Modified: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/mbeans-descriptors.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/mbeans-descriptors.xml?rev=739449&r1=739448&r2=739449&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/mbeans-descriptors.xml (original)
+++ tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/mbeans-descriptors.xml Fri Jan 30 23:32:38 2009
@@ -17,7 +17,7 @@
 -->
 <mbeans-descriptors>
 
-  <mbean description="Reports " domain="Tomcat" group="jdbc-pool" name="SlowQueryReportJmx" 
+  <mbean description="Reports " domain="tomcat.jdbc" group="jdbc-pool" name="SlowQueryReportJmx" 
          type="org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReportJmx">
 
     <attribute description="The name of the connection pool this Jmx bean is representing" name="poolName" type="java.lang.String" writeable="false"/>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org