ThreadFactory 线程池工厂

时间:2022-02-16 06:14:41
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; public class ThreadFactory {
private static ExecutorService threadpool = Executors.newFixedThreadPool(200); public static ExecutorService getThreadpool() {
return threadpool;
}
}

固定线程池默认抛弃策略,线程超过数量被抛弃不执行,但是队列默认数量是整形的最大数,一般是超不过队列数量加线程池数量

spring线程池

import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import com.yundaex.common.dao.context.SpringContext;

public class ThreadFactory {
private static ThreadPoolTaskExecutor threadpool = (ThreadPoolTaskExecutor) SpringContext.getBean("taskExecutor"); public static ThreadPoolTaskExecutor getThreadpool() {
return threadpool;
}
}