Skip to content

Commit

Permalink
调整SQL解析器默认线程池.
Browse files Browse the repository at this point in the history
  • Loading branch information
nieqiurong committed Apr 5, 2024
1 parent 21aecd4 commit 29e9705
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,36 @@
import net.sf.jsqlparser.statement.Statements;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
* @author miemie
* @since 2023-08-05
*/
public class JsqlParserGlobal {

/**
* 默认线程数大小
*
* @since 3.5.6
*/
public static final int DEFAULT_THREAD_SIZE = (Runtime.getRuntime().availableProcessors() + 1) / 2;

/**
* 默认解析处理线程池
* <p>注意: 由于项目情况,机器配置等不一样因素,请自行根据情况创建指定线程池.</p>
*
* @see java.util.concurrent.ThreadPoolExecutor
* @since 3.5.6
*/
public static ExecutorService executorService = Executors.newFixedThreadPool((Runtime.getRuntime().availableProcessors() + 1) / 2);
public static ExecutorService executorService = new ThreadPoolExecutor(DEFAULT_THREAD_SIZE, DEFAULT_THREAD_SIZE, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(), r -> {
Thread thread = new Thread(r);
thread.setName("mybatis-plus-jsqlParser-" + thread.getId());
thread.setDaemon(true);
return thread;
});

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

0 comments on commit 29e9705

Please sign in to comment.