From: Date: January 10 2007 5:17pm Subject: Connector/J commit: r6284 - branches/branch_5_0/connector-j branches/branch_5_0/connector-j/src/com/mysql/jdbc branches/branch_5_0/connector-j/src/testsuite/regression trunk/connector-j trunk/connector-j/src/com/mysql/jdbc trunk/connector-j/src/testsuite/regression List-Archive: http://lists.mysql.com/commits/17860 X-Bug: 25514 Message-Id: <200701101617.l0AGHBqq002983@bk-internal.mysql.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modified: branches/branch_5_0/connector-j/CHANGES branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java branches/branch_5_0/connector-j/src/testsuite/regression/ConnectionRegressionTest.java trunk/connector-j/CHANGES trunk/connector-j/src/com/mysql/jdbc/Connection.java trunk/connector-j/src/testsuite/regression/ConnectionRegressionTest.java Log: Fixed BUG#25514 - Timer instance used for Statement.setQueryTimeout() created per-connection, rather than per-VM, causing memory leak Modified: branches/branch_5_0/connector-j/CHANGES =================================================================== --- branches/branch_5_0/connector-j/CHANGES 2007-01-10 01:01:58 UTC (rev 6283) +++ branches/branch_5_0/connector-j/CHANGES 2007-01-10 16:17:09 UTC (rev 6284) @@ -49,6 +49,9 @@ - Fixed BUG#21438 - Driver sending nanoseconds to server for timestamps when using server-side prepared statements, when server expects microseconds. + + - Fixed BUG#25514 - Timer instance used for Statement.setQueryTimeout() + created per-connection, rather than per-VM, causing memory leak. 10-20-06 - Version 5.0.4 Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java =================================================================== --- branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java 2007-01-10 01:01:58 UTC (rev 6283) +++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java 2007-01-10 16:17:09 UTC (rev 6284) @@ -1068,6 +1068,8 @@ TRANSACTION_REPEATABLE_READ)); mapTransIsolationNameToValue.put("SERIALIZABLE", new Integer( TRANSACTION_SERIALIZABLE)); + + cancelTimer = new Timer("MySQL Statement timeout timer", false); } protected static SQLException appendMessageToException(SQLException sqlEx, @@ -1438,7 +1440,7 @@ String databaseToConnectTo, String url) throws SQLException { this.charsetToNumBytesMap = new HashMap(); - this.cancelTimer = new Timer(true); + this.connectionCreationTimeMillis = System.currentTimeMillis(); this.pointOfOrigin = new Throwable(); Modified: branches/branch_5_0/connector-j/src/testsuite/regression/ConnectionRegressionTest.java =================================================================== --- branches/branch_5_0/connector-j/src/testsuite/regression/ConnectionRegressionTest.java 2007-01-10 01:01:58 UTC (rev 6283) +++ branches/branch_5_0/connector-j/src/testsuite/regression/ConnectionRegressionTest.java 2007-01-10 16:17:09 UTC (rev 6284) @@ -1791,4 +1791,52 @@ } } } + + /** + * Tests fix for BUG#25514 - Timer instance used for Statement.setQueryTimeout() + * created per-connection, rather than per-VM, causing memory leak. + * + * @throws Exception if the test fails. + */ + public void testBug25514() throws Exception { + + for (int i = 0; i < 10; i++) { + getConnectionWithProps(null).close(); + } + + ThreadGroup root = Thread.currentThread().getThreadGroup().getParent(); + + while (root.getParent() != null) { + root = root.getParent(); + } + + int numThreadsNamedTimer = findNamedThreadCount(root, "MySQL Statement timeout timer"); + + assertEquals(1, numThreadsNamedTimer); + } + + private int findNamedThreadCount(ThreadGroup group, String nameStart) { + + int count = 0; + + int numThreads = group.activeCount(); + Thread[] threads = new Thread[numThreads*2]; + numThreads = group.enumerate(threads, false); + + for (int i=0; i