Author: rdonkin Date: Thu Nov 10 13:29:25 2005 New Revision: 332379 URL: http://svn.apache.org/viewcvs?rev=332379&view=rev Log: Breaks dependency from GenericObjectPool to commons-collections. Submitted by Sandy McArthur. Issue #37428.
Modified: jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericObjectPool.java Modified: jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericObjectPool.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericObjectPool.java?rev=332379&r1=332378&r2=332379&view=diff ============================================================================== --- jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericObjectPool.java (original) +++ jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/GenericObjectPool.java Thu Nov 10 13:29:25 2005 @@ -18,8 +18,9 @@ import java.util.Iterator; import java.util.NoSuchElementException; +import java.util.LinkedList; +import java.util.ListIterator; -import org.apache.commons.collections.CursorableLinkedList; import org.apache.commons.pool.BaseObjectPool; import org.apache.commons.pool.ObjectPool; import org.apache.commons.pool.PoolableObjectFactory; @@ -417,7 +418,7 @@ _softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis; _testWhileIdle = testWhileIdle; - _pool = new CursorableLinkedList(); + _pool = new LinkedList(); startEvictor(_timeBetweenEvictionRunsMillis); } @@ -949,10 +950,6 @@ clear(); _pool = null; _factory = null; - if(null != _evictionCursor) { - _evictionCursor.close(); - _evictionCursor = null; - } startEvictor(-1L); super.close(); } @@ -970,19 +967,18 @@ public synchronized void evict() throws Exception { assertOpen(); if(!_pool.isEmpty()) { - if(null == _evictionCursor) { - _evictionCursor = (_pool.cursor(_pool.size())); - } else if(!_evictionCursor.hasPrevious()) { - _evictionCursor.close(); - _evictionCursor = (_pool.cursor(_pool.size())); + ListIterator iter; + if (evictLastIndex < 0) { + iter = _pool.listIterator(_pool.size()); + } else { + iter = _pool.listIterator(evictLastIndex); } for(int i=0,m=getNumTests();i<m;i++) { - if(!_evictionCursor.hasPrevious()) { - _evictionCursor.close(); - _evictionCursor = (_pool.cursor(_pool.size())); + if(!iter.hasPrevious()) { + iter = _pool.listIterator(_pool.size()); } else { boolean removeObject = false; - ObjectTimestampPair pair = (ObjectTimestampPair)(_evictionCursor.previous()); + ObjectTimestampPair pair = (ObjectTimestampPair)(iter.previous()); long idleTimeMilis = System.currentTimeMillis() - pair.tstamp; if ((_minEvictableIdleTimeMillis > 0) && (idleTimeMilis > _minEvictableIdleTimeMillis)) { @@ -1013,7 +1009,7 @@ } if(removeObject) { try { - _evictionCursor.remove(); + iter.remove(); _factory.destroyObject(pair.value); } catch(Exception e) { ; // ignored @@ -1021,6 +1017,7 @@ } } } + evictLastIndex = iter.previousIndex(); // resume from here } // if !empty } @@ -1122,7 +1119,7 @@ /** * The idle object evictor thread. - * @see #setTimeBetweenEvictionRunsMillis + * @see GenericObjectPool#setTimeBetweenEvictionRunsMillis */ class Evictor implements Runnable { private boolean _cancelled = false; @@ -1154,12 +1151,6 @@ // ignored } } - synchronized(GenericObjectPool.this) { - if(null != _evictionCursor) { - _evictionCursor.close(); - _evictionCursor = null; - } - } } } @@ -1331,7 +1322,7 @@ private long _softMinEvictableIdleTimeMillis = DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS; /** My pool. */ - private CursorableLinkedList _pool = null; + private LinkedList _pool = null; /** My [EMAIL PROTECTED] PoolableObjectFactory}. */ private PoolableObjectFactory _factory = null; @@ -1347,5 +1338,8 @@ */ private Evictor _evictor = null; - private CursorableLinkedList.Cursor _evictionCursor = null; + /** + * Position in the _pool where the _evictor last stopped. + */ + private int evictLastIndex = -1; } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]