commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwaldh...@apache.org
Subject cvs commit: jakarta-commons/pool/src/java/org/apache/commons/pool/impl GenericObjectPool.java SoftReferenceObjectPool.java StackObjectPool.java
Date Mon, 22 Apr 2002 23:43:18 GMT
rwaldhoff    02/04/22 16:43:18

  Modified:    pool/src/java/org/apache/commons/pool/impl
                        GenericObjectPool.java SoftReferenceObjectPool.java
                        StackObjectPool.java
  Log:
  applied changes described in bug 7519
  http://nagoya.apache.org/bugzilla/show_bug.cgi?id=7519
  
  Revision  Changes    Path
  1.3       +27 -14    jakarta-commons/pool/src/java/org/apache/commons/pool/impl/GenericObjectPool.java
  
  Index: GenericObjectPool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/pool/src/java/org/apache/commons/pool/impl/GenericObjectPool.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- GenericObjectPool.java	17 Mar 2002 14:55:21 -0000	1.2
  +++ GenericObjectPool.java	22 Apr 2002 23:43:18 -0000	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/pool/src/java/org/apache/commons/pool/impl/GenericObjectPool.java,v
1.2 2002/03/17 14:55:21 rwaldhoff Exp $
  - * $Revision: 1.2 $
  - * $Date: 2002/03/17 14:55:21 $
  + * $Header: /home/cvs/jakarta-commons/pool/src/java/org/apache/commons/pool/impl/GenericObjectPool.java,v
1.3 2002/04/22 23:43:18 rwaldhoff Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/04/22 23:43:18 $
    *
    * ====================================================================
    *
  @@ -159,7 +159,7 @@
    * </ul>
    * @see GenericKeyedObjectPool
    * @author Rodney Waldhoff
  - * @version $Id: GenericObjectPool.java,v 1.2 2002/03/17 14:55:21 rwaldhoff Exp $
  + * @version $Id: GenericObjectPool.java,v 1.3 2002/04/22 23:43:18 rwaldhoff Exp $
    */
   public class GenericObjectPool implements ObjectPool {
   
  @@ -792,24 +792,37 @@
           return _pool.size();
       }
   
  -    public synchronized void returnObject(Object obj) throws Exception {
  -        _numActive--;
  -        if(_maxIdle > 0 && (_pool.size() >= _maxIdle || (_testOnReturn &&
!_factory.validateObject(obj)))) {
  +    public void returnObject(Object obj) throws Exception {
  +        boolean success = true;
  +        if(_testOnReturn && !(_factory.validateObject(obj))) {
  +            success = false;
  +        } else {
               try {
                   _factory.passivateObject(obj);
               } catch(Exception e) {
  -                ; // ignored, we're throwing it out anway
  +                success = false;
               }
  -            _factory.destroyObject(obj);
  -        } else {
  -            try {
  -                _factory.passivateObject(obj);
  +        }
  +
  +        boolean shouldDestroy = !success;
  +
  +        synchronized(this) {
  +            _numActive--;
  +            if((_maxIdle > 0) && (_pool.size() >= _maxIdle)) {
  +                shouldDestroy = true;
  +            } else if(success) {
                   _pool.addFirst(new ObjectTimestampPair(obj));
  -            } catch(Exception e) {
  +            }
  +            notifyAll(); // _numActive has changed
  +        }
  +
  +        if(shouldDestroy) {
  +            try {
                   _factory.destroyObject(obj);
  +            } catch(Exception e) {
  +                // ignored
               }
           }
  -        notifyAll(); // _numActive has changed
       }
   
       synchronized public void close() throws Exception {
  
  
  
  1.3       +31 -15    jakarta-commons/pool/src/java/org/apache/commons/pool/impl/SoftReferenceObjectPool.java
  
  Index: SoftReferenceObjectPool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/pool/src/java/org/apache/commons/pool/impl/SoftReferenceObjectPool.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SoftReferenceObjectPool.java	19 Mar 2002 18:01:49 -0000	1.2
  +++ SoftReferenceObjectPool.java	22 Apr 2002 23:43:18 -0000	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/pool/src/java/org/apache/commons/pool/impl/SoftReferenceObjectPool.java,v
1.2 2002/03/19 18:01:49 rwaldhoff Exp $
  - * $Revision: 1.2 $
  - * $Date: 2002/03/19 18:01:49 $
  + * $Header: /home/cvs/jakarta-commons/pool/src/java/org/apache/commons/pool/impl/SoftReferenceObjectPool.java,v
1.3 2002/04/22 23:43:18 rwaldhoff Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/04/22 23:43:18 $
    *
    * ====================================================================
    *
  @@ -74,7 +74,7 @@
    * {@link ObjectPool}.
    *
    * @author Rodney Waldhoff
  - * @version $Revision: 1.2 $ $Date: 2002/03/19 18:01:49 $
  + * @version $Revision: 1.3 $ $Date: 2002/04/22 23:43:18 $
    */
   public class SoftReferenceObjectPool implements ObjectPool {
       public SoftReferenceObjectPool() {
  @@ -120,19 +120,35 @@
           return obj;
       }
   
  -    public synchronized void returnObject(Object obj) throws Exception {
  -        _numActive--;
  -        if(null == _factory || _factory.validateObject(obj)) {
  -            if(null != _factory) {
  -                try {
  -                    _factory.passivateObject(obj);
  -                } catch(Exception e) {
  -                    _factory.destroyObject(obj);
  -                    return;
  -                }
  +    public void returnObject(Object obj) throws Exception {
  +        boolean success = true;
  +        if(!(_factory.validateObject(obj))) {
  +            success = false;
  +        } else {
  +            try {
  +                _factory.passivateObject(obj);
  +            } catch(Exception e) {
  +                success = false;
  +            }
  +        }
  +
  +        boolean shouldDestroy = !success;
  +        synchronized(this) {
  +            _numActive--;
  +            if(success) {
  +                _pool.add(new SoftReference(obj));
               }
  +            notifyAll(); // _numActive has changed
           }
  -        _pool.add(new SoftReference(obj));
  +
  +        if(shouldDestroy) {
  +            try {
  +                _factory.destroyObject(obj);
  +            } catch(Exception e) {
  +                // ignored
  +            }
  +        }
  +
       }
   
       /** Returns an approximation not less than the of the number of idle instances in the
pool. */
  
  
  
  1.3       +29 -21    jakarta-commons/pool/src/java/org/apache/commons/pool/impl/StackObjectPool.java
  
  Index: StackObjectPool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/pool/src/java/org/apache/commons/pool/impl/StackObjectPool.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- StackObjectPool.java	17 Mar 2002 14:55:21 -0000	1.2
  +++ StackObjectPool.java	22 Apr 2002 23:43:18 -0000	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/pool/src/java/org/apache/commons/pool/impl/StackObjectPool.java,v
1.2 2002/03/17 14:55:21 rwaldhoff Exp $
  - * $Revision: 1.2 $
  - * $Date: 2002/03/17 14:55:21 $
  + * $Header: /home/cvs/jakarta-commons/pool/src/java/org/apache/commons/pool/impl/StackObjectPool.java,v
1.3 2002/04/22 23:43:18 rwaldhoff Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/04/22 23:43:18 $
    *
    * ====================================================================
    *
  @@ -79,7 +79,7 @@
    * artificial limits.
    *
    * @author Rodney Waldhoff
  - * @version $Id: StackObjectPool.java,v 1.2 2002/03/17 14:55:21 rwaldhoff Exp $
  + * @version $Id: StackObjectPool.java,v 1.3 2002/04/22 23:43:18 rwaldhoff Exp $
    */
   public class StackObjectPool implements ObjectPool {
       /**
  @@ -172,27 +172,35 @@
           return obj;
       }
   
  -    public synchronized void returnObject(Object obj) throws Exception {
  -        _numActive--;
  -        if(null == _factory || _factory.validateObject(obj)) {
  -            if(null != _factory) {
  -                try {
  -                    _factory.passivateObject(obj);
  -                } catch(Exception e) {
  -                    _factory.destroyObject(obj);
  -                    return;
  -                }
  +    public void returnObject(Object obj) throws Exception {
  +        boolean success = true;
  +        if(!(_factory.validateObject(obj))) {
  +            success = false;
  +        } else {
  +            try {
  +                _factory.passivateObject(obj);
  +            } catch(Exception e) {
  +                success = false;
               }
  -            if(_pool.size() < _maxSleeping) {
  +        }
  +
  +        boolean shouldDestroy = !success;
  +
  +        synchronized(this) {
  +            _numActive--;
  +            if(_pool.size() >= _maxSleeping) {
  +                shouldDestroy = true;
  +            } else if(success) {
                   _pool.push(obj);
  -            } else {
  -                if(null != _factory) {
  -                    _factory.destroyObject(obj);
  -                }
               }
  -        } else {
  -            if(null != _factory) {
  +            notifyAll(); // _numActive has changed
  +        }
  +
  +        if(shouldDestroy) {
  +            try {
                   _factory.destroyObject(obj);
  +            } catch(Exception e) {
  +                // ignored
               }
           }
       }
  
  
  

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


Mime
View raw message