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



##########
File path: src/main/java/org/apache/commons/pool2/impl/EvictionTimer.java
##########
@@ -129,4 +167,45 @@ public Thread newThread(final Runnable runnable) {
             return thread;
         }
     }
+
+    /**
+     * Task that removes references to abandoned tasks and shuts
+     * down the executor if there are no live tasks left.
+     */
+    private static class Reaper implements Runnable {
+        @Override
+        public void run() {
+            synchronized (EvictionTimer.class) {
+                for (Entry<WeakReference<Runnable>, WeakRunner> entry : 
taskMap.entrySet()) {
+                    if (entry.getKey().get() == null) {
+                        executor.remove(entry.getValue());
+                        taskMap.remove(entry.getKey());
+                    }
+                }
+                if (taskMap.isEmpty() && executor != null) {
+                    executor.shutdown();
+                    executor.setCorePoolSize(0);
+                    executor = null;
+                }
+            }
+        }
+    }
+
+    /**
+     * Runnable that runs the referent of a weak reference. When the referent 
is no
+     * no longer reachable, run is no-op.
+     */
+    private static class WeakRunner implements Runnable {
+        private final WeakReference<Runnable> ref;
+        public WeakRunner(WeakReference<Runnable> ref) {
+           this.ref = ref;
+        }
+        @Override
+        public void run() {
+            final Runnable task = ref.get();
+            if (task != null) {
+                task.run();
+            }
+        }

Review comment:
       Doh!  Yes, that makes things clearer.  Fixed.




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