|
@@ -98,6 +98,21 @@ public class DBUtil {
|
|
|
implementation.getMethod("setMaxPoolSize", Integer.class).invoke(c3po, maxPoolSize);
|
|
|
implementation.getMethod("setPreferredTestQuery", String.class).invoke(c3po,
|
|
|
"select 1 from dual");
|
|
|
+
|
|
|
+ Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ Class<?> dataSourcesClass = Class
|
|
|
+ .forName("com.mchange.v2.c3p0.DataSources");
|
|
|
+ dataSourcesClass.getMethod("destroy", DataSource.class, Boolean.class)
|
|
|
+ .invoke(null, c3po);
|
|
|
+ DataSources.destroy(c3po);
|
|
|
+ } catch (Exception e) {
|
|
|
+ LOG.error("[JDBC] Fail to destroy dataSource. dataSourceName="
|
|
|
+ + dataSourceName, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }));
|
|
|
}
|
|
|
// druid
|
|
|
else if (simpleName.endsWith("DruidDataSource")) {
|