dirkv 2003/08/26 08:00:06
Modified: pool/src/java/org/apache/commons/pool/impl
GenericKeyedObjectPool.java
Log:
use startEvictor method like the GenericObjectPool
Revision Changes Path
1.21 +31 -24
jakarta-commons/pool/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java
Index: GenericKeyedObjectPool.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/pool/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- GenericKeyedObjectPool.java 26 Aug 2003 14:14:15 -0000 1.20
+++ GenericKeyedObjectPool.java 26 Aug 2003 15:00:06 -0000 1.21
@@ -441,12 +441,7 @@
_activeMap = new HashMap();
_poolList = new CursorableLinkedList();
- if(_timeBetweenEvictionRunsMillis > 0) {
- _evictor = new Evictor();
- Thread t = new Thread(_evictor);
- t.setDaemon(true);
- t.start();
- }
+ startEvictor(_timeBetweenEvictionRunsMillis);
}
//--- public methods ---------------------------------------------
@@ -665,19 +660,8 @@
* @see #getTimeBetweenEvictionRunsMillis
*/
public synchronized void setTimeBetweenEvictionRunsMillis(long
timeBetweenEvictionRunsMillis) {
- if(_timeBetweenEvictionRunsMillis > 0 && timeBetweenEvictionRunsMillis <=
0) {
- _evictor.cancel();
- _evictor = null;
- _timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
- } else if(_timeBetweenEvictionRunsMillis <= 0 &&
timeBetweenEvictionRunsMillis > 0) {
- _timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
- _evictor = new Evictor();
- Thread t = new Thread(_evictor);
- t.setDaemon(true);
- t.start();
- } else {
- _timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
- }
+ _timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
+ startEvictor(_timeBetweenEvictionRunsMillis);
}
/**
@@ -1091,7 +1075,25 @@
}
}
- //--- package and private methods -----------------------------------------
+ //--- non-public methods ----------------------------------------
+
+ /**
+ * Start the eviction thread or service, or when
+ * <i>delay</i> is non-positive, stop it
+ * if it is already running.
+ */
+ protected synchronized void startEvictor(long delay) {
+ if(null != _evictor) {
+ _evictor.cancel();
+ _evictor = null;
+ }
+ if(delay > 0) {
+ _evictor = new Evictor(delay);
+ Thread t = new Thread(_evictor);
+ t.setDaemon(true);
+ t.start();
+ }
+ }
synchronized String debugInfo() {
StringBuffer buf = new StringBuffer();
@@ -1172,7 +1174,12 @@
* @see #setTimeBetweenEvictionRunsMillis
*/
class Evictor implements Runnable {
- protected boolean _cancelled = false;
+ private boolean _cancelled = false;
+ private long _delay = 0L;
+
+ public Evictor(long delay) {
+ _delay = delay;
+ }
void cancel() {
_cancelled = true;
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]