Bug #26706 A separate timer is getting created for every Connection creation
Submitted: 28 Feb 2007 0:49 Modified: 28 Feb 2007 4:41
Reporter: Odysseus Levy Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version: OS:
Assigned to: CPU Architecture:Any

[28 Feb 2007 0:49] Odysseus Levy
Description:
When running Jprofiler against our application I noticed at lot of Timer-xxx threads are getting created over time. This only happens when using the 5.04 jdbc driver and not when using the 3.11 version of the driver (the version we were previously using).

In the constructor of the Connection object I see that a new Timer object is getting created and stored in the static cancelTimer object. This looks like a bug -- the constructor should not be setting a static object -- that will cause the static variable to constantly get over-written.

Instead, the cancelTimer should just be created just once when the Connection class is created.

I've marked this as S2 because it represents a memory leak and there is no work-around (except to use older version of the driver).

How to repeat:
Create lots of connections -- monitor the Timer-xxx threads that are created. You should see one Timer thread for each connection created.

Suggested fix:
Change definition of cancelTimer from:

	private static Timer cancelTimer;

to:
	private static Timer cancelTimer = new Timer()

And remove the cancelTimer = new Timer() line from the constructor.
[28 Feb 2007 4:41] Mark Matthews
Duplicate of BUG#25514 (fixed for 5.0.5 soon to be released, fix has also been available in the nightly snapshot builds for awhile now, see http://downloads.mysql.com/snapshots.php#connector-j).