import lombok.Getter;
import javax.annotation.PostConstruct;
import java.util.concurrent.*;
//创建一个线城池
public class LogOptionThreadPool {
private static final ThreadFactory mThreadFactory = new ThreadFactory() {
//线程的名字
public Thread newThread(Runnable r) {
return new Thread(r,"OperationLogThread");
}
};
BlockingQueue<Runnable> workQueue=new LinkedBlockingDeque<>(1000);
@Getter
ThreadPoolExecutor logThread;
@PostConstruct
public void init(){
logThread=new ThreadPoolExecutor(2,2,60, TimeUnit.SECONDS,workQueue,
mThreadFactory, new ThreadPoolExecutor.CallerRunsPolicy());
logThread.prestartAllCoreThreads();
}
}
//在service中注入该线程,调用execute方法,开启线程,线程里面放入参数