tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fha...@apache.org
Subject svn commit: r770890 - in /tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool: ConnectionPool.java PoolProperties.java PooledConnection.java
Date Sat, 02 May 2009 04:57:47 GMT
Author: fhanik
Date: Sat May  2 04:57:47 2009
New Revision: 770890

URL: http://svn.apache.org/viewvc?rev=770890&view=rev
Log:
Implement a hard limit, the 'optimistic' sizing limit is way to optimistic, and can let the
pool grow a bit too fast.
A hard limit stays hard.
Clean up pooled connection a bit


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/PoolProperties.java
    tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.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=770890&r1=770889&r2=770890&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 Sat
May  2 04:57:47 2009
@@ -56,7 +56,7 @@
     //===============================================================================
     //         INSTANCE/QUICK ACCESS VARIABLE
     //===============================================================================
-    
+    private AtomicInteger size = new AtomicInteger(0);
     /**
      * All the information about the connection pool
      */
@@ -169,7 +169,7 @@
      * @return int
      */
     public int getSize() {
-        return idle.size()+busy.size();
+        return size.get();
     }
 
     /**
@@ -409,7 +409,7 @@
             if (jmxPool!=null) {
                 jmxPool.notify(org.apache.tomcat.jdbc.pool.jmx.ConnectionPool.NOTIFY_ABANDON,
trace);
             }
-            con.abandon();
+            release(con);
             //we've asynchronously reduced the number of connections
             //we could have threads stuck in idle.poll(timeout) that will never be notified
             if (waitcount.get()>0) idle.offer(new PooledConnection(poolProperties,this));
@@ -429,6 +429,7 @@
             con.lock();
             con.release();
         } finally {
+            size.addAndGet(-1);
             con.unlock();
         }
     }
@@ -463,7 +464,8 @@
             //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()) {
+            if (size.get() < getPoolProperties().getMaxActive()) {
+                size.addAndGet(1);
                 return createConnection(now, con);
             } //end if
 
@@ -757,7 +759,7 @@
                         continue;
                     if (!con.validate(PooledConnection.VALIDATE_IDLE)) {
                         idle.remove(con);
-                        con.release();
+                        release(con);
                     }
                 } finally {
                     con.unlock();

Modified: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java?rev=770890&r1=770889&r2=770890&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java (original)
+++ tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java Sat
May  2 04:57:47 2009
@@ -68,7 +68,7 @@
     protected String initSQL;
     protected boolean testOnConnect =false;
     protected String jdbcInterceptors=null;
-    protected boolean fairQueue = true;
+    protected boolean fairQueue = false;
     protected boolean useEquals = false;
     protected int abandonWhenPercentageFull = 0;
     protected long maxAge = 0;

Modified: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java?rev=770890&r1=770889&r2=770890&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java
(original)
+++ tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java
Sat May  2 04:57:47 2009
@@ -68,35 +68,35 @@
     /**
      * The underlying database connection
      */
-    protected java.sql.Connection connection;
+    private java.sql.Connection connection;
     /**
      * When we track abandon traces, this string holds the thread dump
      */
-    protected String abandonTrace = null;
+    private String abandonTrace = null;
     /**
      * Timestamp the connection was last 'touched' by the pool
      */
-    protected long timestamp;
+    private long timestamp;
     /**
      * Lock for this connection only
      */
-    protected ReentrantReadWriteLock lock = new ReentrantReadWriteLock(false);
+    private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(false);
     /**
      * Set to true if this connection has been discarded by the pool
      */
-    protected boolean discarded = false;
+    private boolean discarded = false;
     /**
      * The Timestamp when the last time the connect() method was called successfully
      */
-    protected volatile long lastConnected = -1;
+    private volatile long lastConnected = -1;
     /**
      * timestamp to keep track of validation intervals
      */
-    protected long lastValidated = System.currentTimeMillis();
+    private volatile long lastValidated = System.currentTimeMillis();
     /**
      * The instance number for this connection
      */
-    protected int instanceCount = 0;
+    private int instanceCount = 0;
     /**
      * The parent
      */
@@ -107,7 +107,7 @@
      * so that we don't create a new list of interceptors each time we borrow
      * the connection
      */
-    protected WeakReference<JdbcInterceptor> handler = null;
+    private WeakReference<JdbcInterceptor> handler = null;
     
     
     public PooledConnection(PoolProperties prop, ConnectionPool parent) {
@@ -116,7 +116,7 @@
         this.parent = parent;
     }
 
-    protected void connect() throws SQLException {
+    public void connect() throws SQLException {
         if (connection != null) {
             try {
                 this.disconnect(false);
@@ -178,12 +178,12 @@
         return connection!=null;
     }
 
-    protected void reconnect() throws SQLException {
+    public void reconnect() throws SQLException {
         this.disconnect(false);
         this.connect();
     } //reconnect
 
-    protected void disconnect(boolean finalize) {
+    private void disconnect(boolean finalize) {
         if (isDiscarded()) {
             return;
         }
@@ -215,16 +215,7 @@
         } //end if
     }
 
-    public boolean abandon() {
-        try {
-            disconnect(true);
-        } catch (Exception x) {
-            log.error("", x);
-        } //catch
-        return false;
-    }
-
-    protected boolean doValidate(int action) {
+    private boolean doValidate(int action) {
         if (action == PooledConnection.VALIDATE_BORROW &&
             poolProperties.isTestOnBorrow())
             return true;



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


Mime
View raw message