feat:(1.2.0-beta1): 1. 优化客户端线程池,当获取缓存线程池时才设置并行度
This commit is contained in:
parent
01d24d754a
commit
d4fcc62ba9
2
pom.xml
2
pom.xml
@ -21,7 +21,7 @@
|
|||||||
<java.version>17</java.version>
|
<java.version>17</java.version>
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
<revision>1.1.1</revision>
|
<revision>1.2.0-beta1</revision>
|
||||||
<netty-all.version>4.1.94.Final</netty-all.version>
|
<netty-all.version>4.1.94.Final</netty-all.version>
|
||||||
<hutool-all.version>5.8.25</hutool-all.version>
|
<hutool-all.version>5.8.25</hutool-all.version>
|
||||||
<mybatis-plus.version>3.5.7</mybatis-plus.version>
|
<mybatis-plus.version>3.5.7</mybatis-plus.version>
|
||||||
|
@ -24,13 +24,21 @@ public class ThreadPoolCache {
|
|||||||
|
|
||||||
public static ThreadPoolExecutor createThreadPool(Long taskBatchId, int parallelNum) {
|
public static ThreadPoolExecutor createThreadPool(Long taskBatchId, int parallelNum) {
|
||||||
if (CACHE_THREAD_POOL.containsKey(taskBatchId)) {
|
if (CACHE_THREAD_POOL.containsKey(taskBatchId)) {
|
||||||
return CACHE_THREAD_POOL.get(taskBatchId);
|
ThreadPoolExecutor cacheThreadPool = CACHE_THREAD_POOL.get(taskBatchId);
|
||||||
|
if (cacheThreadPool.getCorePoolSize() == parallelNum) {
|
||||||
|
return cacheThreadPool;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 若能执行到这里只有分片任务(静态分片、MAP、MapReduce)才会需要多线程支持
|
||||||
|
cacheThreadPool.setCorePoolSize(parallelNum);
|
||||||
|
cacheThreadPool.setMaximumPoolSize(parallelNum);
|
||||||
|
return cacheThreadPool;
|
||||||
}
|
}
|
||||||
|
|
||||||
Supplier<ThreadPoolExecutor> supplier = () -> {
|
Supplier<ThreadPoolExecutor> supplier = () -> {
|
||||||
|
|
||||||
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
|
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
|
||||||
parallelNum, parallelNum, 10, TimeUnit.SECONDS, new LinkedBlockingQueue<>(),
|
// 默认情况先只设置一个线程, 只有分片任务(静态分片、MAP、MapReduce)才会需要多线程支持
|
||||||
|
1, 1, 10, TimeUnit.SECONDS, new LinkedBlockingQueue<>(),
|
||||||
new CustomizableThreadFactory(MessageFormat.format("snail-job-job-{0}-", taskBatchId)));
|
new CustomizableThreadFactory(MessageFormat.format("snail-job-job-{0}-", taskBatchId)));
|
||||||
threadPoolExecutor.allowCoreThreadTimeOut(true);
|
threadPoolExecutor.allowCoreThreadTimeOut(true);
|
||||||
return threadPoolExecutor;
|
return threadPoolExecutor;
|
||||||
|
Loading…
Reference in New Issue
Block a user