You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2012/12/03 12:48:27 UTC
svn commit: r1416459 - in /tomcat/tc7.0.x/trunk: ./
modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
Author: markt
Date: Mon Dec 3 11:48:27 2012
New Revision: 1416459
URL: http://svn.apache.org/viewvc?rev=1416459&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=54217
Prevent PoolCleaner instances retaining references to the ConnectionPool which may result in a memory leak.
Modified:
tomcat/tc7.0.x/trunk/ (props changed)
tomcat/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
Merged /tomcat/trunk:r1416458
Modified: tomcat/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java?rev=1416459&r1=1416458&r2=1416459&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java (original)
+++ tomcat/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java Mon Dec 3 11:48:27 2012
@@ -16,6 +16,7 @@
*/
package org.apache.tomcat.jdbc.pool;
+import java.lang.ref.WeakReference;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
@@ -1315,14 +1316,13 @@ public class ConnectionPool {
return poolCleanTimer;
}
- protected class PoolCleaner extends TimerTask {
- protected ConnectionPool pool;
+ protected static class PoolCleaner extends TimerTask {
+ protected WeakReference<ConnectionPool> pool;
protected long sleepTime;
- protected volatile boolean run = true;
protected volatile long lastRun = 0;
PoolCleaner(ConnectionPool pool, long sleepTime) {
- this.pool = pool;
+ this.pool = new WeakReference<ConnectionPool>(pool);
this.sleepTime = sleepTime;
if (sleepTime <= 0) {
log.warn("Database connection pool evicter thread interval is set to 0, defaulting to 30 seconds");
@@ -1334,11 +1334,11 @@ public class ConnectionPool {
@Override
public void run() {
- if (pool.isClosed()) {
- if (pool.getSize() <= 0) {
- run = false;
- }
- } else if ((System.currentTimeMillis() - lastRun) > sleepTime) {
+ ConnectionPool pool = this.pool.get();
+ if (pool == null) {
+ stopRunning();
+ } else if (!pool.isClosed() &&
+ (System.currentTimeMillis() - lastRun) > sleepTime) {
lastRun = System.currentTimeMillis();
try {
if (pool.getPoolProperties().isRemoveAbandoned())
@@ -1350,9 +1350,9 @@ public class ConnectionPool {
pool.testAllIdle();
} catch (Exception x) {
log.error("", x);
- } // catch
- } // end if
- } // run
+ }
+ }
+ }
public void start() {
registerCleaner(this);
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org