This is an automated email from the ASF dual-hosted git repository. rmaucher pushed a commit to branch 10.1.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit df00b82c776761f00e5381e173569fe2d56b539e Author: opencode <[email protected]> AuthorDate: Thu Nov 5 22:55:21 2026 +0100 Document the JMX lifecycle of an abandoned pool Deregistering a published DataSource releases the pool MBean and the child connection and interceptor MBeans, but it does not close the pool. A registered pool MBean holds the pool, and the connection MBeans hold the pooled connections; abandoning a JMX-enabled pool without close() therefore keeps the pool, its sessions and its driver class loader reachable for the life of the JVM. State that requirement on DataSource, StatementCache and ResetAbandonedTimer. This resolves the StatementCache and ResetAbandonedTimer MBean retention findings without a lightweight-resource refactor: in the supported lifecycle those MBeans are released with the pool or its deregistration. --- .../src/main/java/org/apache/tomcat/jdbc/pool/DataSource.java | 6 ++++++ .../apache/tomcat/jdbc/pool/interceptor/ResetAbandonedTimer.java | 5 +++++ .../org/apache/tomcat/jdbc/pool/interceptor/StatementCache.java | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSource.java b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSource.java index d69a1d03b1..bbaa0c1b72 100644 --- a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSource.java +++ b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSource.java @@ -38,6 +38,12 @@ import org.apache.tomcat.jdbc.pool.util.MessageFactory; * A JMX registration made before the pool exists publishes nothing, because there is no pool MBean to publish. Create * the pool before registering the data source, or register it again after the pool has been created, to have the pool * monitored. + * <p> + * Deregistering a published data source releases the pool MBean and the connection and interceptor MBeans published + * below it, but it does not close the pool. A JMX-enabled pool that is no longer wanted must therefore be closed + * before the data source is dropped: while the pool MBean is registered it holds the pool, and the connection MBeans + * hold the pooled connections. Abandoning a registered pool without {@link #close(boolean)} keeps the pool, its + * pooled sessions and its JDBC driver class loader reachable for the life of the JVM. */ public class DataSource extends DataSourceProxy implements javax.sql.DataSource, MBeanRegistration, org.apache.tomcat.jdbc.pool.jmx.ConnectionPoolMBean, javax.sql.ConnectionPoolDataSource { diff --git a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/ResetAbandonedTimer.java b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/ResetAbandonedTimer.java index 138d61c610..5b9e72a746 100644 --- a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/ResetAbandonedTimer.java +++ b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/ResetAbandonedTimer.java @@ -55,6 +55,11 @@ import org.apache.tomcat.jdbc.pool.util.MessageFactory; * {@link org.apache.tomcat.jdbc.pool.PoolConfiguration#setRemoveAbandonedTimeout(int)} that is fairly low, and you * want to reset the abandoned time each time any operation on the connection is performed. This is useful for batch * processing programs that use connections for extensive amount of times. + * <p> + * With JMX enabled, the interceptor publishes an MBean below its connection's MBean. It is released when the + * connection is recycled, when the pool closes, or when the pool MBean is deregistered. A pool that is abandoned + * without being closed keeps its registrations - and through them the pool, its sessions and its driver class loader - + * reachable, so a JMX-enabled pool must be closed before it is dropped. */ public class ResetAbandonedTimer extends AbstractQueryReport implements ResetAbandonedTimerMBean { diff --git a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/StatementCache.java b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/StatementCache.java index 6620e7297d..7e1ac210c5 100644 --- a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/StatementCache.java +++ b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/StatementCache.java @@ -61,6 +61,11 @@ import org.apache.tomcat.jdbc.pool.util.MessageFactory; * it out from under a live cache entry; listed after this one, it makes this cache refuse to park at all, and * statements are closed normally instead of cached. Only {@link StatementFinalizer} and its subclasses are recognised * by that check; a third-party interceptor with the same behaviour is not detected. + * <p> + * With JMX enabled, a cache publishes an MBean below its connection's MBean. It is released when the connection is + * recycled, when the pool closes, or when the pool MBean is deregistered. A pool that is abandoned without being + * closed keeps its registrations - and through them the pool, its sessions and its driver class loader - reachable, so + * a JMX-enabled pool must be closed before it is dropped. */ public class StatementCache extends StatementDecoratorInterceptor implements StatementCacheMBean { private static final Log log = LogFactory.getLog(StatementCache.class); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
