dirkv 2003/08/22 05:49:21
Modified: pool/src/java/org/apache/commons/pool/impl
GenericObjectPool.java
Log:
- all getters & setters synchronized
- invalidateObject method destroyobject de-synchronized
Revision Changes Path
1.26 +36 -35 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.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- GenericObjectPool.java 21 Aug 2003 18:17:35 -0000 1.25
+++ GenericObjectPool.java 22 Aug 2003 12:49:21 -0000 1.26
@@ -447,7 +447,7 @@
* @return the cap on the total number of active instances from my pool.
* @see #setMaxActive
*/
- public int getMaxActive() {
+ public synchronized int getMaxActive() {
return _maxActive;
}
@@ -457,11 +457,9 @@
* Use a negative value for an infinite number of instances.
* @see #getMaxActive
*/
- public void setMaxActive(int maxActive) {
+ public synchronized void setMaxActive(int maxActive) {
_maxActive = maxActive;
- synchronized(this) {
- notifyAll();
- }
+ notifyAll();
}
/**
@@ -472,7 +470,7 @@
* @return one of {@link #WHEN_EXHAUSTED_BLOCK}, {@link #WHEN_EXHAUSTED_FAIL} or {@link
#WHEN_EXHAUSTED_GROW}
* @see #setWhenExhaustedAction
*/
- public byte getWhenExhaustedAction() {
+ public synchronized byte getWhenExhaustedAction() {
return _whenExhaustedAction;
}
@@ -534,6 +532,7 @@
*/
public synchronized void setMaxWait(long maxWait) {
_maxWait = maxWait;
+ notifyAll();
}
/**
@@ -541,7 +540,7 @@
* @return the cap on the number of "idle" instances in the pool.
* @see #setMaxIdle
*/
- public int getMaxIdle() {
+ public synchronized int getMaxIdle() {
return _maxIdle;
}
@@ -552,11 +551,9 @@
* of idle instances.
* @see #getMaxIdle
*/
- public void setMaxIdle(int maxIdle) {
+ public synchronized void setMaxIdle(int maxIdle) {
_maxIdle = maxIdle;
- synchronized(this) {
- notifyAll();
- }
+ notifyAll();
}
/**
@@ -567,11 +564,9 @@
* @param minIdle The minimum number of objects.
* @see #getMinIdle
*/
- public void setMinIdle(int minIdle) {
+ public synchronized void setMinIdle(int minIdle) {
_minIdle = minIdle;
- synchronized(this) {
- notifyAll();
- }
+ notifyAll();
}
/**
@@ -596,7 +591,7 @@
*
* @see #setTestOnBorrow
*/
- public boolean getTestOnBorrow() {
+ public synchronized boolean getTestOnBorrow() {
return _testOnBorrow;
}
@@ -610,7 +605,7 @@
*
* @see #getTestOnBorrow
*/
- public void setTestOnBorrow(boolean testOnBorrow) {
+ public synchronized void setTestOnBorrow(boolean testOnBorrow) {
_testOnBorrow = testOnBorrow;
}
@@ -622,7 +617,7 @@
*
* @see #setTestOnReturn
*/
- public boolean getTestOnReturn() {
+ public synchronized boolean getTestOnReturn() {
return _testOnReturn;
}
@@ -634,7 +629,7 @@
*
* @see #getTestOnReturn
*/
- public void setTestOnReturn(boolean testOnReturn) {
+ public synchronized void setTestOnReturn(boolean testOnReturn) {
_testOnReturn = testOnReturn;
}
@@ -670,7 +665,7 @@
* @see #setNumTestsPerEvictionRun
* @see #setTimeBetweenEvictionRunsMillis
*/
- public int getNumTestsPerEvictionRun() {
+ public synchronized int getNumTestsPerEvictionRun() {
return _numTestsPerEvictionRun;
}
@@ -685,7 +680,7 @@
* @see #getNumTestsPerEvictionRun
* @see #setTimeBetweenEvictionRunsMillis
*/
- public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {
+ public synchronized void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {
_numTestsPerEvictionRun = numTestsPerEvictionRun;
}
@@ -724,7 +719,7 @@
* @see #setTestWhileIdle
* @see #setTimeBetweenEvictionRunsMillis
*/
- public boolean getTestWhileIdle() {
+ public synchronized boolean getTestWhileIdle() {
return _testWhileIdle;
}
@@ -737,7 +732,7 @@
* @see #getTestWhileIdle
* @see #setTimeBetweenEvictionRunsMillis
*/
- public void setTestWhileIdle(boolean testWhileIdle) {
+ public synchronized void setTestWhileIdle(boolean testWhileIdle) {
_testWhileIdle = testWhileIdle;
}
@@ -862,11 +857,17 @@
}
}
- public synchronized void invalidateObject(Object obj) throws Exception {
+ public void invalidateObject(Object obj) throws Exception {
assertOpen();
- _numActive--;
- _factory.destroyObject(obj);
- notifyAll(); // _numActive has changed
+ try {
+ _factory.destroyObject(obj);
+ }
+ finally {
+ synchronized(this) {
+ _numActive--;
+ notifyAll(); // _numActive has changed
+ }
+ }
}
public synchronized void clear() {
@@ -883,12 +884,12 @@
notifyAll(); // num sleeping has changed
}
- public int getNumActive() {
+ public synchronized int getNumActive() {
assertOpen();
return _numActive;
}
- public int getNumIdle() {
+ public synchronized int getNumIdle() {
assertOpen();
return _pool.size();
}
@@ -927,7 +928,7 @@
}
}
- synchronized public void close() throws Exception {
+ public synchronized void close() throws Exception {
clear();
_pool = null;
_factory = null;
@@ -939,7 +940,7 @@
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");
|