Skip to content

Commit

Permalink
增加JVM退出钩子处理.
Browse files Browse the repository at this point in the history
  • Loading branch information
nieqiurong committed Feb 10, 2025
1 parent c4091c9 commit 62dd02e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.statement.Statements;
import org.apache.ibatis.logging.Log;
import org.apache.ibatis.logging.LogFactory;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
Expand All @@ -33,6 +35,8 @@
*/
public class JsqlParserGlobal {

private static final Log LOG = LogFactory.getLog(JsqlParserGlobal.class);

/**
* 默认线程数大小
*
Expand All @@ -54,6 +58,17 @@ public class JsqlParserGlobal {
return thread;
});

static {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
if (!executorService.isShutdown()) {
if (LOG.isDebugEnabled()) {
LOG.debug("close jsqlParser thread pool ...");
}
executorService.shutdown();
}
}, "mybatis-plus-jsqlParser-shutdown-hook"));
}

@Setter
private static JsqlParserFunction<String, Statement> parserSingleFunc = sql -> CCJSqlParserUtil.parse(sql, executorService, null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.statement.Statements;
import org.apache.ibatis.logging.Log;
import org.apache.ibatis.logging.LogFactory;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
Expand All @@ -33,6 +35,8 @@
*/
public class JsqlParserGlobal {

private static final Log LOG = LogFactory.getLog(JsqlParserGlobal.class);

/**
* 默认线程数大小
*
Expand All @@ -54,6 +58,17 @@ public class JsqlParserGlobal {
return thread;
});

static {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
if (!executorService.isShutdown()) {
if (LOG.isDebugEnabled()) {
LOG.debug("close jsqlParser thread pool ...");
}
executorService.shutdown();
}
}, "mybatis-plus-jsqlParser-shutdown-hook"));
}

@Setter
private static JsqlParserFunction<String, Statement> parserSingleFunc = sql -> CCJSqlParserUtil.parse(sql, executorService, null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.statement.Statements;
import org.apache.ibatis.logging.Log;
import org.apache.ibatis.logging.LogFactory;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
Expand All @@ -33,6 +35,8 @@
*/
public class JsqlParserGlobal {

private static final Log LOG = LogFactory.getLog(JsqlParserGlobal.class);

/**
* 默认线程数大小
*
Expand All @@ -54,6 +58,17 @@ public class JsqlParserGlobal {
return thread;
});

static {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
if (!executorService.isShutdown()) {
if (LOG.isDebugEnabled()) {
LOG.debug("close jsqlParser thread pool ...");
}
executorService.shutdown();
}
}, "mybatis-plus-jsqlParser-shutdown-hook"));
}

@Setter
private static JsqlParserFunction<String, Statement> parserSingleFunc = sql -> CCJSqlParserUtil.parse(sql, executorService, null);

Expand Down

0 comments on commit 62dd02e

Please sign in to comment.