Author: markt
Date: Tue Sep 23 13:21:10 2014
New Revision: 1627008

URL: http://svn.apache.org/r1627008
Log:
Port code clean up and a memory leak fix from Pool2 trunk

Modified:
    tomcat/trunk/java/org/apache/tomcat/dbcp/pool2/impl/EvictionTimer.java

Modified: tomcat/trunk/java/org/apache/tomcat/dbcp/pool2/impl/EvictionTimer.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/dbcp/pool2/impl/EvictionTimer.java?rev=1627008&r1=1627007&r2=1627008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/dbcp/pool2/impl/EvictionTimer.java 
(original)
+++ tomcat/trunk/java/org/apache/tomcat/dbcp/pool2/impl/EvictionTimer.java Tue 
Sep 23 13:21:10 2014
@@ -39,10 +39,10 @@ import java.util.TimerTask;
 class EvictionTimer {
 
     /** Timer instance */
-    private static Timer _timer; //@GuardedBy("this")
+    private static Timer _timer; //@GuardedBy("EvictionTimer.class")
 
     /** Static usage count tracker */
-    private static int _usageCount; //@GuardedBy("this")
+    private static int _usageCount; //@GuardedBy("EvictionTimer.class")
 
     /** Prevent instantiation */
     private EvictionTimer() {
@@ -67,7 +67,7 @@ class EvictionTimer {
             try {
                 AccessController.doPrivileged(new PrivilegedSetTccl(
                         EvictionTimer.class.getClassLoader()));
-                _timer = new Timer("commons-pool-EvictionTimer", true);
+                _timer = AccessController.doPrivileged(new 
PrivilegedNewEvictionTimer());
             } finally {
                 AccessController.doPrivileged(new PrivilegedSetTccl(ccl));
             }
@@ -129,4 +129,22 @@ class EvictionTimer {
         }
     }
 
+    /**
+     * {@link PrivilegedAction} used to create a new Timer. Creating the timer
+     * with a privileged action means the associated Thread does not inherit 
the
+     * current access control context. In a container environment, inheriting
+     * the current access control context is likely to result in retaining a
+     * reference to the thread context class loader which would be a memory
+     * leak.
+     */
+    private static class PrivilegedNewEvictionTimer implements 
PrivilegedAction<Timer> {
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override
+        public Timer run() {
+            return new Timer("commons-pool-EvictionTimer", true);
+        }
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to