- 线程池定义(可防序列化攻击)
package com.yang.utils;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* @author yangjx
* @date 2021/8/26 10:56
* @description
*/
public enum MedDetailThreadPool {
/**
* 日志记录
*/
LOG_POOL(new ThreadPoolExecutor(
16,
32,
30,
TimeUnit.MINUTES,
new ArrayBlockingQueue<Runnable>(2048),
new ThreadPoolExecutor.CallerRunsPolicy()
));
/**
* 线程池
*/
private final ThreadPoolExecutor pool;
MedDetailThreadPool(ThreadPoolExecutor pool) {
this.pool = pool;
}
public ThreadPoolExecutor getPool() {
return pool;
}
}
- 使用线程池
MedDetailThreadPool.LOG_POOL.getPool().execute(() -> System.out.println());
标签:java,枚举,线程,import,Java,MedDetailThreadPool,pool,ThreadPoolExecutor
From: https://www.cnblogs.com/JaxYoun/p/17091739.html