|
29 | 29 | import arjdbc.jdbc.Callable; |
30 | 30 |
|
31 | 31 | import java.lang.reflect.Field; |
| 32 | +import java.lang.reflect.InvocationTargetException; |
32 | 33 | import java.lang.reflect.Proxy; |
33 | 34 | import java.sql.Connection; |
34 | 35 | import java.sql.PreparedStatement; |
@@ -234,10 +235,48 @@ protected String caseConvertIdentifierForRails(final Connection connection, fina |
234 | 235 | @Override |
235 | 236 | protected Connection newConnection() throws RaiseException, SQLException { |
236 | 237 | final Connection connection = super.newConnection(); |
| 238 | + if ( doStopCleanupThread() ) shutdownCleanupThread(); |
237 | 239 | if ( doKillCancelTimer(connection) ) killCancelTimer(connection); |
238 | 240 | return connection; |
239 | 241 | } |
240 | 242 |
|
| 243 | + private static Boolean stopCleanupThread; |
| 244 | + static { |
| 245 | + final String stopThread = System.getProperty("arjdbc.mysql.stop_cleanup_thread"); |
| 246 | + if ( stopThread != null ) stopCleanupThread = Boolean.parseBoolean(stopThread); |
| 247 | + } |
| 248 | + |
| 249 | + private static boolean doStopCleanupThread() throws SQLException { |
| 250 | + // TODO when refactoring default behavior to "stop" consider not doing so for JNDI |
| 251 | + return stopCleanupThread != null && stopCleanupThread.booleanValue(); |
| 252 | + } |
| 253 | + |
| 254 | + private static boolean cleanupThreadShutdown; |
| 255 | + |
| 256 | + private static void shutdownCleanupThread() { |
| 257 | + if ( cleanupThreadShutdown ) return; |
| 258 | + try { |
| 259 | + Class threadClass = Class.forName("com.mysql.jdbc.AbandonedConnectionCleanupThread"); |
| 260 | + threadClass.getMethod("shutdown").invoke(null); |
| 261 | + } |
| 262 | + catch (ClassNotFoundException e) { |
| 263 | + debugMessage("INFO: missing MySQL JDBC cleanup thread: " + e); |
| 264 | + } |
| 265 | + catch (NoSuchMethodException e) { |
| 266 | + debugMessage( e.toString() ); |
| 267 | + } |
| 268 | + catch (IllegalAccessException e) { |
| 269 | + debugMessage( e.toString() ); |
| 270 | + } |
| 271 | + catch (InvocationTargetException e) { |
| 272 | + debugMessage( e.getTargetException().toString() ); |
| 273 | + } |
| 274 | + catch (SecurityException e) { |
| 275 | + debugMessage( e.toString() ); |
| 276 | + } |
| 277 | + finally { cleanupThreadShutdown = true; } |
| 278 | + } |
| 279 | + |
241 | 280 | private static Boolean killCancelTimer; |
242 | 281 | static { |
243 | 282 | final String killTimer = System.getProperty("arjdbc.mysql.kill_cancel_timer"); |
|
0 commit comments