You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ma...@apache.org on 2014/09/23 15:15:56 UTC
svn commit: r1627004 - in /commons/proper/pool/trunk/src: changes/changes.xml
main/java/org/apache/commons/pool2/impl/EvictionTimer.java
Author: markt
Date: Tue Sep 23 13:15:56 2014
New Revision: 1627004
URL: http://svn.apache.org/r1627004
Log:
Prevent potential memory leaks with using an Evictor in a container environment.
Modified:
commons/proper/pool/trunk/src/changes/changes.xml
commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/EvictionTimer.java
Modified: commons/proper/pool/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/changes/changes.xml?rev=1627004&r1=1627003&r2=1627004&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/changes/changes.xml (original)
+++ commons/proper/pool/trunk/src/changes/changes.xml Tue Sep 23 13:15:56 2014
@@ -84,6 +84,10 @@ The <action> type attribute can be add,u
Prevent potential memory leaks when the Pool is dereferenced without being
closed.
</action>
+ <action dev="markt" type="fix">
+ Prevent potential memory leaks with using an Evictor in a container
+ environment.
+ </action>
</release>
<release version="2.2" date="2014-02-24" description=
"This is a maintenance release that adds a new testOnCreate configuration option
Modified: commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/EvictionTimer.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/EvictionTimer.java?rev=1627004&r1=1627003&r2=1627004&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/EvictionTimer.java (original)
+++ commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/EvictionTimer.java Tue Sep 23 13:15:56 2014
@@ -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);
+ }
+ }
}