psteitz commented on a change in pull request #32:
URL: https://github.com/apache/commons-pool/pull/32#discussion_r459811492
##########
File path:
src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java
##########
@@ -783,12 +783,21 @@ final void assertOpen() throws IllegalStateException {
*/
final void startEvictor(final long delay) {
synchronized (evictionLock) {
- EvictionTimer.cancel(evictor, evictorShutdownTimeoutMillis,
TimeUnit.MILLISECONDS);
- evictor = null;
- evictionIterator = null;
- if (delay > 0) {
- evictor = new Evictor();
- EvictionTimer.schedule(evictor, delay, delay);
+ if (evictor == null) { // Starting evictor for the first time or
after a cancel
+ if (delay > 0) { // Starting new evictor
+ evictor = new Evictor();
+ EvictionTimer.schedule(evictor, delay, delay);
+ }
+ } else { // Stop or restart of existing evictor
+ if (delay > 0) { // Restart
+ EvictionTimer.cancel(evictor,
evictorShutdownTimeoutMillis, TimeUnit.MILLISECONDS, true);
+ evictor = null;
+ evictionIterator = null;
+ evictor = new Evictor();
+ EvictionTimer.schedule(evictor, delay, delay);
+ } else { // Stopping evictor
Review comment:
I went ahead and added the sync. Maybe not beautiful code, but
effective and efficient. The cancel and schedule calls need to acquire the
EvictionTimer class lock, so adding the sync around the block does not add any
overhead.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]