定义线程池
@Slf4j
@Component
public class PalmThreadPool {
public static int CORE_POOL_SIZE = 4;
private final AtomicInteger atomicInteger = new AtomicInteger(1);
public ScheduledThreadPoolExecutor poolExecutor = new ScheduledThreadPoolExecutor(CORE_POOL_SIZE, r -> {
Thread thread = new Thread(r, "bbc-palm-" + atomicInteger.getAndIncrement());
log.debug("Create thread {}", thread.getName());
return thread;
}, (r, e) -> log.error("thread pool rejected"));
}
使用线程池
this.palmThreadPool.poolExecutor.schedule(() -> {
Input input= new Input();
studentService.add(input);
}, 0, TimeUnit.SECONDS);