把要注入的Service,通过构造传过去
1.controller层
@Autowired
private ThreadPoolTaskExecutor taskExecutor;
@Autowired
private TaginfoService taginfoService;
@RequestMapping("/test")
@ResponseBody
public Object index(String mac){
Thread thread = new DealData2(taginfoService);
taskExecutor.execute(thread);
return null;
}
2.线程类
public class DealData2 extends Thread {
private TaginfoService taginfoService;
public DealData2(TaginfoService taginfoService) {
this.taginfoService = taginfoService;
}
@Override
public void run() {
String sta="5cc9987678";
List
//判断是否存在
if(taginfos!=null&&taginfos.size()>0){
System.out.println("标签不为空==数值"+taginfos.toString());
}else{
System.out.println("数据库中不存在此");
}
}
}
3.spring中配置线程池,配置在spring-dao.xml下
第一步:配置.properties
taskExecutor.corePoolSize=100
taskExecutor.keepAliveSeconds=10
taskExecutor.maxPoolSize=100
taskExecutor.queueCapacity=20
第二步: