psteitz commented on a change in pull request #32:
URL: https://github.com/apache/commons-pool/pull/32#discussion_r458466835



##########
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:
       Good catch.  I got confused about lock scope (evictionlock is not quite 
enough to protect here :).  I guess syncing the whole block on EvictionTimer 
class lock would prevent that, but only for low probability efficiency gain.  
Not sure how to fix this other than that.  Did not change this.
   
   Thanks for review!




----------------------------------------------------------------
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]


Reply via email to