<dependency>
<groupId>org.apache.skywalking</groupId>
<artifactId>apm-toolkit-trace</artifactId>
<version>xxx</version>
</dependency>
public class ThreadPoolExecutor extends java.util.concurrent.ThreadPoolExecutor {
private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();
private static final int corePoolSize = Math.max(2, Math.min(CPU_COUNT - 1, 4));
private static final int iomaximumPoolSize = CPU_COUNT * 2;
private static final int cpumaximumPoolSize = CPU_COUNT + 1;
private static final long keepAliveTime = 30L;
private static final int queueLength = 100;
public static ExecutorService iocachedThreadPool = null;
public static ExecutorService cpucachedThreadPool = null;
public static ScheduledExecutorService scheduledThreadPool = null;
public static ExecutorService newIOCachedThreadPool() {
if (iocachedThreadPool == null) {
synchronized (ThreadPoolExecutor.class) {
if (iocachedThreadPool == null) {
iocachedThreadPool = new java.util.concurrent.ThreadPoolExecutor(corePoolSize, iomaximumPoolSize,
60L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(queueLength));
}
}
}
return iocachedThreadPool;
}
public static ExecutorService newCPUCachedThreadPool() {
if (cpucachedThreadPool == null) {
synchronized (ThreadPoolExecutor.class) {
if (cpucachedThreadPool == null) {
cpucachedThreadPool = new ThreadPoolExecutor(corePoolSize, cpumaximumPoolSize,
keepAliveTime, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(queueLength));
}
}
}
return cpucachedThreadPool;
}
public static ScheduledExecutorService newScheduledThreadPool() {
if (scheduledThreadPool == null) {
synchronized (ThreadPoolExecutor.class) {
if (scheduledThreadPool == null) {
scheduledThreadPool = Executors.newScheduledThreadPool(cpumaximumPoolSize);
}
}
}
return scheduledThreadPool;
}
public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue) {
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
}
public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory) {
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory);
}
public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, RejectedExecutionHandler handler) {
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, handler);
}
public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory, RejectedExecutionHandler handler) {
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, handler);
}
@Override
public void execute(Runnable task) {
super.execute(task);
}
@Override
public <T> Future<T> submit(Callable<T> task) {
return super.submit(task);
}
@Override
public Future<?> submit(Runnable task) {
return super.submit(task);
}
}