Some more concurrency testing
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 10 Jul 2009 21:38:16 +0000 (21:38 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 10 Jul 2009 21:38:16 +0000 (21:38 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@793116 13f79535-47bb-0310-9956-ffa450edef68

modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java
modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java
modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java
modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java
modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/TestConcurrency.java

index b02b06c..53a765c 100644 (file)
@@ -847,7 +847,7 @@ public class ConnectionPool {
                     if (busy.contains(con))
                         continue;
                     long time = con.getTimestamp();
-                    if (((now - time) > con.getReleaseTime()) && (getSize()>getPoolProperties().getMinIdle())) {
+                    if ((con.getReleaseTime()>0) && ((now - time) > con.getReleaseTime()) && (getSize()>getPoolProperties().getMinIdle())) {
                         release(con);
                         idle.remove(con);
                         setToNull = true;
index 6883bd8..30f4fc4 100644 (file)
@@ -108,6 +108,7 @@ public class DataSourceFactory implements ObjectFactory {
     protected final static String PROP_FAIR_QUEUE = "fairQueue";
     
     protected static final String PROP_USE_EQUALS = "useEquals";
+    protected static final String PROP_USE_CON_LOCK = "useLock";
     
     public static final int UNKNOWN_TRANSACTIONISOLATION = -1;
     
@@ -151,7 +152,8 @@ public class DataSourceFactory implements ObjectFactory {
         PROP_USE_EQUALS,
         OBJECT_NAME,
         PROP_ABANDONWHENPERCENTAGEFULL,
-        PROP_MAXAGE
+        PROP_MAXAGE,
+        PROP_USE_CON_LOCK
     };
 
     // -------------------------------------------------- ObjectFactory Methods
@@ -424,6 +426,11 @@ public class DataSourceFactory implements ObjectFactory {
             poolProperties.setMaxAge(Long.parseLong(value));
         }
         
+        value = properties.getProperty(PROP_USE_CON_LOCK);
+        if (value != null) {
+            poolProperties.setUseLock(Boolean.parseBoolean(value));
+        }
+        
         return poolProperties;
     }
 
index 17d5ee9..e8d7615 100644 (file)
@@ -287,6 +287,10 @@ public class DataSourceProxy  {
         this.getPoolProperties().setFairQueue(fairQueue);
     }
     
+    public void setUseLock(boolean useLock) {
+        this.getPoolProperties().setUseLock(useLock);
+    }
+    
     public void setDefaultCatalog(String catalog) {
         this.getPoolProperties().setDefaultCatalog(catalog);
     }
index 9c7d29b..cd01c5c 100644 (file)
@@ -72,7 +72,7 @@ public class PoolProperties {
     protected boolean useEquals = false;
     protected int abandonWhenPercentageFull = 0;
     protected long maxAge = 0;
-    protected boolean useLock = true;
+    protected boolean useLock = false;
     private InterceptorDefinition[] interceptors = null;
     
     public void setAbandonWhenPercentageFull(int percentage) {
index f01b2a0..111c974 100644 (file)
@@ -77,7 +77,7 @@ public class PooledConnection {
     /**
      * Timestamp the connection was last 'touched' by the pool
      */
-    private long timestamp;
+    private volatile long timestamp;
     /**
      * Lock for this connection only
      */
index 23b4ef0..7aa2965 100644 (file)
@@ -91,17 +91,16 @@ public class TestConcurrency extends DefaultTestCase {
     
     public void testBrutal() throws Exception {
         ds.getPoolProperties().setRemoveAbandoned(false);
-        ds.getPoolProperties().setMinEvictableIdleTimeMillis(-1);
+        ds.getPoolProperties().setMinEvictableIdleTimeMillis(10);
         ds.getPoolProperties().setTimeBetweenEvictionRunsMillis(-1);
         ds.getConnection().close();
-        final int iter = 1000 * 10;
+        final int iter = 100000 * 10;
         final AtomicInteger loopcount = new AtomicInteger(0);
         final Runnable run = new Runnable() {
             public void run() {
                 try {
                     while (loopcount.incrementAndGet() < iter) {
                         Connection con = ds.getConnection();
-                        Thread.sleep(10);
                         con.close();
                     }
                 }catch (Exception x) {
@@ -136,7 +135,7 @@ public class TestConcurrency extends DefaultTestCase {
         assertEquals("Size comparison:",10, ds.getPool().getSize());
         assertEquals("Idle comparison:",10, ds.getPool().getIdle());
         assertEquals("Used comparison:",0, ds.getPool().getActive());
-        assertEquals("Connect count",10,Driver.connectCount.get());
+        assertEquals("Connect count",10,Driver.connectCount.get()-Driver.disconnectCount.get());
             
     }