commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r781023 - in /commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl: TestGenericKeyedObjectPool.java TestGenericObjectPool.java
Date Tue, 02 Jun 2009 12:49:43 GMT
Author: sebb
Date: Tue Jun  2 12:49:43 2009
New Revision: 781023

URL: http://svn.apache.org/viewvc?rev=781023&view=rev
Log:
Improve thread safety of TestThread by making all configuration fields final

Modified:
    commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPool.java
    commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java

Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPool.java?rev=781023&r1=781022&r2=781023&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPool.java
(original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPool.java
Tue Jun  2 12:49:43 2009
@@ -1313,20 +1313,22 @@
 
     static class TestThread implements Runnable {
         private final java.util.Random _random = new java.util.Random();
-        private KeyedObjectPool _pool = null;
+        
+        // Thread config items
+        private final KeyedObjectPool _pool;
+        private final int _iter;
+        private final int _delay;
+
         private volatile boolean _complete = false;
         private volatile boolean _failed = false;
         private volatile Exception _exception;
-        private int _iter = 100;
-        private int _delay = 50;
 
         public TestThread(KeyedObjectPool pool) {
-            _pool = pool;
+            this(pool, 100, 50);
         }
 
         public TestThread(KeyedObjectPool pool, int iter) {
-            _pool = pool;
-            _iter = iter;
+            this(pool, iter, 50);
         }
 
         public TestThread(KeyedObjectPool pool, int iter, int delay) {
@@ -1356,7 +1358,6 @@
                     obj = _pool.borrowObject(key);
                 } catch(Exception e) {
                     _exception = e;
-                    e.printStackTrace();
                     _failed = true;
                     _complete = true;
                     break;
@@ -1371,7 +1372,6 @@
                     _pool.returnObject(key,obj);
                 } catch(Exception e) {
                     _exception = e;
-                    e.printStackTrace();
                     _failed = true;
                     _complete = true;
                     break;

Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java?rev=781023&r1=781022&r2=781023&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java
(original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java
Tue Jun  2 12:49:43 2009
@@ -1110,41 +1110,43 @@
         runTestThreads(5, 10, 50);
     }
 
-    class TestThread implements Runnable {
+    static class TestThread implements Runnable {
         private final java.util.Random _random = new java.util.Random();
-        private ObjectPool _pool = null;
+        
+        // Thread config items
+        private final ObjectPool _pool;
+        private final int _iter;
+        private final int _delay;
+        private final boolean _randomDelay;
+        private final Object _expectedObject;
+        
         private volatile boolean _complete = false;
         private volatile boolean _failed = false;
-        private int _iter = 100;
-        private int _delay = 50;
-        private boolean _randomDelay = true;
-        private Object _expectedObject = null;
         private volatile Throwable _error;
 
         public TestThread(ObjectPool pool) {
-            _pool = pool;
+            this(pool, 100, 50, true, null);
         }
 
         public TestThread(ObjectPool pool, int iter) {
-            _pool = pool;
-            _iter = iter;
+            this(pool, iter, 50, true, null);
         }
 
         public TestThread(ObjectPool pool, int iter, int delay) {
-            _pool = pool;
-            _iter = iter;
-            _delay = delay;
+            this(pool, iter, delay, true, null);
         }
         
         public TestThread(ObjectPool pool, int iter, int delay,
                 boolean randomDelay) {
+            this(pool, iter, delay, true, null);
+        }
+
+        public TestThread(ObjectPool pool, int iter, int delay,
+                boolean randomDelay, Object obj) {
             _pool = pool;
             _iter = iter;
             _delay = delay;
             _randomDelay = randomDelay;
-        }
-
-        public void setExpectedObject(Object obj) {
             _expectedObject = obj;
         }
 
@@ -1411,8 +1413,7 @@
         // Start threads to borrow objects
         TestThread[] threads = new TestThread[numThreads];
         for(int i=0;i<numThreads;i++) {
-            threads[i] = new TestThread(pool, 1, 500, false);
-            threads[i].setExpectedObject(String.valueOf(i % maxActive));
+            threads[i] = new TestThread(pool, 1, 500, false, String.valueOf(i % maxActive));
             Thread t = new Thread(threads[i]);
             t.start();
             // Short delay to ensure threads start in correct order



Mime
View raw message