MySQLStatement does leak TimerThread

Description

Hi,

the MySQLStatement does start a TimerThread to handle the timeouts (which are e.g. applied in transactions).

Stopping the webapplication does leak those thread because it is never stopped and the complete classloader fails to get garbage collected.
My current workaround is, to call this in the contextDestroyed method of a webapp listener:

1 2 3 4 5 6 7 8 9 10 11 12 try { final Class<?> clazz = ReflectionUtils.getClassForName("org.mariadb.jdbc.MySQLStatement"); final Field f = clazz.getDeclaredField("timer"); f.setAccessible(true); Timer timer = (Timer) f.get(null); if (timer != null) { timer.cancel(); } timer = null; } catch (ClassNotFoundException | IllegalAccessException | NoSuchFieldException | SecurityException e) { // ignore }

I've done similar for mysql, to stop the scheduler started to destroy connections.
The difference is that there is an api call, a static method shutdown, to do this and i need no hacks to get that timer variable.

1 2 3 4 5 6 7 8 9 10 11 12 try { final Class<?> clazz = ReflectionUtils.getClassForName("com.mysql.jdbc.AbandonedConnectionCleanupThread"); MethodUtils.invokeExactStaticMethod(clazz, "shutdown", null); } catch (ClassNotFoundException e) { // ignore } catch (NoSuchMethodException e) { // ignore } catch (IllegalAccessException e) { // ignore } catch (InvocationTargetException e) { // ignore }

Maybe you can implement similar.

And if you do so, it would be nice if you can call the constructor, which does take a name for the Timer, e.g. MariaDBTimeoutStatementTimer, or something like this, to get rid of the "Timer-0" name in the thread overview to know what "Timer-0" is about for.

Environment

JDK 1.7.x, Tomcat 7.0.42

Status

Assignee

Vladislav Vaintroub

Reporter

Torsten Krah

Labels

None

External issue ID

None

External issue ID

None

Fix versions

Affects versions

1.1.3

Priority

Minor
Configure