No need to instantiate a new driver instance each time, simply reuse the one we got
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 4 Jan 2011 18:37:44 +0000 (18:37 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 4 Jan 2011 18:37:44 +0000 (18:37 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1055137 13f79535-47bb-0310-9956-ffa450edef68

modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java
modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/AlternateUsernameTest.java

index 526bc60..4f622fe 100644 (file)
@@ -74,7 +74,7 @@ public class PooledConnection {
     /**
      * If using a XAConnection underneath.
      */
-    private volatile javax.sql.XAConnection xaConnection;
+    protected volatile javax.sql.XAConnection xaConnection;
     /**
      * When we track abandon traces, this string holds the thread dump
      */
@@ -117,6 +117,8 @@ public class PooledConnection {
     
     private volatile boolean suspect = false;
     
+    private java.sql.Driver driver = null;
+    
     /**
      * Constructor
      * @param prop - pool properties
@@ -229,10 +231,12 @@ public class PooledConnection {
         }
     }
     protected void connectUsingDriver() throws SQLException {
-        java.sql.Driver driver = null;
+        
         try {
-            driver = (java.sql.Driver) Class.forName(poolProperties.getDriverClassName(),
-                                                     true, PooledConnection.class.getClassLoader()).newInstance();
+            if (driver==null)
+                driver = (java.sql.Driver) Class.forName(poolProperties.getDriverClassName(),
+                                                         true, PooledConnection.class.getClassLoader()
+                                                         ).newInstance();
         } catch (java.lang.Exception cn) {
             if (log.isDebugEnabled()) {
                 log.debug("Unable to instantiate JDBC driver.", cn);
index dcdc079..0ea3e2a 100644 (file)
@@ -34,7 +34,7 @@ import org.apache.tomcat.jdbc.test.driver.Driver;
 
 public class AlternateUsernameTest extends DefaultTestCase {
 
-    private static final int iterations = (new Random(System.currentTimeMillis())).nextInt(1000000)+100000;
+    private static final int iterations = 500000; //(new Random(System.currentTimeMillis())).nextInt(1000000)+100000;
     public AlternateUsernameTest(String name) {
         super(name);
     }
@@ -44,13 +44,15 @@ public class AlternateUsernameTest extends DefaultTestCase {
     
     private void testUsername(boolean allowUsernameChange) throws Exception {
         long start = System.currentTimeMillis();
+        int withoutuser =10;
+        int withuser = withoutuser;
         this.init();
+        this.datasource.setMaxActive(withuser+withoutuser);
         this.datasource.setDriverClassName(Driver.class.getName());
         this.datasource.setUrl("jdbc:tomcat:test");
         this.datasource.setAlternateUsernameAllowed(allowUsernameChange);
         this.datasource.getConnection().close();
-        int withoutuser =10;
-        int withuser = withoutuser;
+        
         TestRunner[] runners = new TestRunner[withuser+withoutuser];
         for (int i=0; i<withuser; i++) {
             TestRunner with = new TestRunner("foo","bar",datasource.getPoolProperties().getUsername(),datasource.getPoolProperties().getPassword());