Details
-
Bug
-
Status: Closed (View Workflow)
-
Minor
-
Resolution: Fixed
-
1.1.3
-
None
-
None
-
JDK 1.7.x, Tomcat 7.0.42
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:
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.
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.