commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r328923 - /jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/SoftReferenceObjectPool.java
Date Thu, 27 Oct 2005 19:02:28 GMT
Author: rdonkin
Date: Thu Oct 27 12:02:25 2005
New Revision: 328923

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

Modified:
    jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/SoftReferenceObjectPool.java

Modified: jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/SoftReferenceObjectPool.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/SoftReferenceObjectPool.java?rev=328923&r1=328922&r2=328923&view=diff
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/SoftReferenceObjectPool.java
(original)
+++ jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/SoftReferenceObjectPool.java
Thu Oct 27 12:02:25 2005
@@ -78,7 +78,7 @@
         return obj;
     }
 
-    public void returnObject(Object obj) throws Exception {
+    public synchronized void returnObject(Object obj) throws Exception {
         assertOpen();
         boolean success = true;
         if(!(_factory.validateObject(obj))) {
@@ -92,13 +92,11 @@
         }
 
         boolean shouldDestroy = !success;
-        synchronized(this) {
-            _numActive--;
-            if(success) {
-                _pool.add(new SoftReference(obj));
-            }
-            notifyAll(); // _numActive has changed
+        _numActive--;
+        if(success) {
+            _pool.add(new SoftReference(obj));
         }
+        notifyAll(); // _numActive has changed
 
         if(shouldDestroy) {
             try {
@@ -121,20 +119,21 @@
      * Create an object, and place it into the pool.
      * addObject() is useful for "pre-loading" a pool with idle objects.
      */
-    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.
+        returnObject(obj);
     }
 
     /** Returns an approximation not less than the of the number of idle instances in the
pool. */
-    public int getNumIdle() {
+    public synchronized int getNumIdle() {
+        assertOpen();
         return _pool.size();
     }
 
-    public int getNumActive() {
+    public synchronized int getNumActive() {
+        assertOpen();
         return _numActive;
     }
 
@@ -156,14 +155,14 @@
         _pool.clear();
     }
 
-    synchronized public void close() throws Exception {
+    public synchronized void close() throws Exception {
         clear();
         _pool = null;
         _factory = null;
         super.close();
     }
 
-    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