42 lines
1.3 KiB
Java
42 lines
1.3 KiB
Java
package com.ruoyi.yunxin;
|
|
|
|
import com.alibaba.ttl.threadpool.TtlExecutors;
|
|
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
|
|
|
import java.util.concurrent.*;
|
|
|
|
/**
|
|
* 线程变量定义
|
|
* <p>created on 2023/3/3 11:16</p>
|
|
* @author ZL
|
|
*/
|
|
public class YunExecutor {
|
|
|
|
// private final static int CPU_NUM = Runtime.getRuntime().availableProcessors();
|
|
|
|
private final static int CPU_NUM = 5;
|
|
|
|
public static Executor YUN_EXECUTOR;
|
|
|
|
static {
|
|
YUN_EXECUTOR = new ThreadPoolExecutor(CPU_NUM,
|
|
CPU_NUM << 2,
|
|
5,
|
|
TimeUnit.SECONDS,
|
|
new ArrayBlockingQueue<>(5),
|
|
init("yunxinThreadPoll-%d"),
|
|
new ThreadPoolExecutor.CallerRunsPolicy());
|
|
// YUN_EXECUTOR = TtlExecutors.getTtlExecutor(roomExecutor);
|
|
}
|
|
|
|
private static ThreadFactory init(String nameFormat){
|
|
return new ThreadFactoryBuilder().setNameFormat(nameFormat).build();
|
|
}
|
|
|
|
private static ThreadPoolExecutor initExecutor(int corePoolSize, int maxPoolSize, int keepAliveTime, TimeUnit timeUnit,
|
|
BlockingQueue<Runnable> workQueue, String nameFormat){
|
|
return new ThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveTime, timeUnit, workQueue,
|
|
init(nameFormat));
|
|
}
|
|
}
|