On 1 September 2011 13:51, <ma...@apache.org> wrote: > Author: markt > Date: Thu Sep 1 12:51:04 2011 > New Revision: 1164053 > > URL: http://svn.apache.org/viewvc?rev=1164053&view=rev > Log: > Make close() thread safe and ensure multiple calls to close() are handled > correctly > > Modified: > > commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java > > commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPool.java > > Modified: > commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java > URL: > http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java?rev=1164053&r1=1164052&r2=1164053&view=diff > ============================================================================== > --- > commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java > (original) > +++ > commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java > Thu Sep 1 12:51:04 2011 > @@ -1093,15 +1093,26 @@ public class GenericKeyedObjectPool<K,T> > */ > @Override > public void close() throws Exception { > - super.close(); > - clear(); > - evictionIterator = null; > - evictionKeyIterator = null; > - startEvictor(-1L); > - if (oname != null) { > - > ManagementFactory.getPlatformMBeanServer().unregisterMBean(oname); > - oname = null; > + if (isClosed()) { > + return; > } > + > + synchronized (closeLock) { > + if (isClosed()) { > + return; > + } > + > + super.close(); > + clear(); > + evictionIterator = null; > + evictionKeyIterator = null; > + startEvictor(-1L); > + if (oname != null) { > + ManagementFactory.getPlatformMBeanServer().unregisterMBean( > + oname);
oname = null; // ?? > + } > + } > + > } > > > @@ -1947,6 +1958,9 @@ public class GenericKeyedObjectPool<K,T> > */ > private K evictionKey = null; > > + /** Object used to ensure closed() is only called once. */ > + private final Object closeLock = new Object(); > + > // JMX specific attributes > private static final int AVERAGE_TIMING_STATS_CACHE_SIZE = 100; > private AtomicLong borrowedCount = new AtomicLong(0); > > Modified: > commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPool.java > URL: > http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPool.java?rev=1164053&r1=1164052&r2=1164053&view=diff > ============================================================================== > --- > commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPool.java > (original) > +++ > commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPool.java > Thu Sep 1 12:51:04 2011 > @@ -1002,12 +1002,22 @@ public class GenericObjectPool<T> extend > */ > @Override > public void close() throws Exception { > - super.close(); > - clear(); > - startEvictor(-1L); > - if (oname != null) { > - > ManagementFactory.getPlatformMBeanServer().unregisterMBean(oname); > - oname = null; > + if (isClosed()) { > + return; > + } > + > + synchronized (closeLock) { > + if (isClosed()) { > + return; > + } > + > + super.close(); > + clear(); > + startEvictor(-1L); > + if (oname != null) { > + ManagementFactory.getPlatformMBeanServer().unregisterMBean( > + oname); oname = null; // ?? > + } > } > } > > @@ -1541,6 +1551,9 @@ public class GenericObjectPool<T> extend > /** An iterator for {@link #idleObjects} that is used by the evictor. */ > private Iterator<PooledObject<T>> evictionIterator = null; > > + /** Object used to ensure closed() is only called once. */ > + private final Object closeLock = new Object(); > + > // JMX specific attributes > private static final int AVERAGE_TIMING_STATS_CACHE_SIZE = 100; > private AtomicLong borrowedCount = new AtomicLong(0); > > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org For additional commands, e-mail: dev-h...@commons.apache.org