commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r328749 - in /jakarta/commons/proper/pool/trunk: project.xml src/java/org/apache/commons/pool/impl/StackObjectPool.java
Date Wed, 26 Oct 2005 22:00:31 GMT
Author: rdonkin
Date: Wed Oct 26 15:00:24 2005
New Revision: 328749

URL: http://svn.apache.org/viewcvs?rev=328749&view=rev
Log:
Added missed synchronization. Submitted by Sandy McArthur. Issue #37226. Thanks to Mayur Naik
for discovering and reporting these issues.

Modified:
    jakarta/commons/proper/pool/trunk/project.xml
    jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/StackObjectPool.java

Modified: jakarta/commons/proper/pool/trunk/project.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/project.xml?rev=328749&r1=328748&r2=328749&view=diff
==============================================================================
--- jakarta/commons/proper/pool/trunk/project.xml (original)
+++ jakarta/commons/proper/pool/trunk/project.xml Wed Oct 26 15:00:24 2005
@@ -140,6 +140,10 @@
       <name>Todd Carmichael</name>
       <email>toddc@concur.com</email>
     </contributor>
+    <contributor>
+      <name>Sandy McArthur</name>
+      <email>Sandy AT McArthur DOT org</email>
+    </contributor>
   </contributors>
   
   <dependencies>

Modified: jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/StackObjectPool.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/StackObjectPool.java?rev=328749&r1=328748&r2=328749&view=diff
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/StackObjectPool.java
(original)
+++ jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/StackObjectPool.java
Wed Oct 26 15:00:24 2005
@@ -138,7 +138,7 @@
         return obj;
     }
 
-    public void returnObject(Object obj) throws Exception {
+    public synchronized void returnObject(Object obj) throws Exception {
         assertOpen();
         boolean success = true;
         if(null != _factory) {
@@ -155,19 +155,17 @@
 
         boolean shouldDestroy = !success;
 
-        synchronized(this) {
-            _numActive--;
-            if (success) {
-                Object toBeDestroyed = null;
-                if(_pool.size() >= _maxSleeping) {
-                    shouldDestroy = true;
-                    toBeDestroyed = _pool.remove(0); // remove the stalest object
-                }
-                _pool.push(obj);
-                obj = toBeDestroyed; // swap returned obj with the stalest one so it can
be destroyed
+        _numActive--;
+        if (success) {
+            Object toBeDestroyed = null;
+            if(_pool.size() >= _maxSleeping) {
+                shouldDestroy = true;
+                toBeDestroyed = _pool.remove(0); // remove the stalest object
             }
-            notifyAll(); // _numActive has changed
+            _pool.push(obj);
+            obj = toBeDestroyed; // swap returned obj with the stalest one so it can be destroyed
         }
+        notifyAll(); // _numActive has changed
 
         if(shouldDestroy) { // by constructor, shouldDestroy is false when _factory is null
             try {
@@ -187,12 +185,12 @@
         notifyAll(); // _numActive has changed
     }
 
-    public int getNumIdle() {
+    public synchronized int getNumIdle() {
         assertOpen();
         return _pool.size();
     }
 
-    public int getNumActive() {
+    public synchronized int getNumActive() {
         assertOpen();
         return _numActive;
     }
@@ -212,7 +210,7 @@
         _pool.clear();
     }
 
-    synchronized public void close() throws Exception {
+    public synchronized void close() throws Exception {
         clear();
         _pool = null;
         _factory = null;
@@ -224,15 +222,14 @@
      * addObject() is useful for "pre-loading" a pool with idle objects.
      * @throws Exception when the {@link #_factory} has a problem creating an object.
      */
-    public void addObject() throws Exception {
+    public synchronized void addObject() throws Exception {
+        assertOpen();
         Object obj = _factory.makeObject();
-        synchronized(this) {
-            _numActive++;   // A little slimy - must do this because returnObject decrements
it.
-            this.returnObject(obj);
-        }
+        _numActive++;   // A little slimy - must do this because returnObject decrements
it.
+        this.returnObject(obj);
     }
 
-    synchronized public void setFactory(PoolableObjectFactory factory) throws IllegalStateException
{
+    public synchronized void setFactory(PoolableObjectFactory factory) throws IllegalStateException
{
         assertOpen();
         if(0 < getNumActive()) {
             throw new IllegalStateException("Objects are already active");



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


Mime
View raw message