5 changed files with 45 additions and 14 deletions
@ -0,0 +1,40 @@
|
||||
package com.logpm.report.util; |
||||
|
||||
import cn.hutool.core.thread.ExecutorBuilder; |
||||
import cn.hutool.core.thread.ThreadFactoryBuilder; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
import java.util.concurrent.ExecutorService; |
||||
|
||||
/** |
||||
* @author zhaoqiaobo |
||||
* @create 2024-03-14 10:26 |
||||
*/ |
||||
@Slf4j |
||||
public class ThreadPoolUtil { |
||||
|
||||
private ThreadPoolUtil() { |
||||
} |
||||
|
||||
//构建线程池
|
||||
public static ExecutorService executor = null; |
||||
static { |
||||
init(); |
||||
} |
||||
|
||||
synchronized public static void init() { |
||||
if (null != executor) { |
||||
executor.shutdownNow(); |
||||
} |
||||
executor = ExecutorBuilder.create() |
||||
.setCorePoolSize(8) |
||||
.setMaxPoolSize(20) |
||||
.setThreadFactory(ThreadFactoryBuilder.create().setNamePrefix("logpm-report-").build()) |
||||
.useSynchronousQueue().build(); |
||||
} |
||||
|
||||
public static ExecutorService getThreadPool(){ |
||||
return executor; |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue