1.自定义线程在spring中的入参
多线程不被spring管理,所以@autowired注入不了
①将service从外部作为自定义的线程类的构造方法的变量传入,然后直接调用该service的方法
②将ApplicationContext上线文作为变量用构造方法传入,(TaskService)ApplicationContext.getBean("taskService")用上下文创建bean,此时TaskService的实现类上需要制定name如@Service("taskService")
2.线程池
ThreadPoolTaskExecutor 来自于spring-context包
①线程池的初始化(核心线程、活跃时间、最大线程、队列数量)
if(taskExecutor == null){
synchronized (this) {
if(taskExecutor == null){
taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(Integer.parseInt(DeploymentConfig.getProperty("threadPool.corePoolSize")));
taskExecutor.setKeepAliveSeconds(Integer.parseInt(DeploymentConfig.getProperty("threadPool.keepAliveSeconds")));
taskExecutor.setMaxPoolSize(Integer.p