67,513
社区成员
发帖
与我相关
我的任务
分享
@Override
public String execute() throws Exception {
saveOnSelfModels();
StartThread sendRun = new StartThread();
sendRun.setOnShelfMap(onShelfMap);
sendRun.start();
return SUCCESS;
}
private ExecutorService executorService;
public StartThread(){
initExecuteService();
}
public void initExecuteService(){
executorService = Executors.newFixedThreadPool(Constants.THREAD_POOL_SIZE);
}
@Override
public void run() {
//first send
List<SendEmergencyThread> sendList = new ArrayList<SendEmergencyThread>();
Set<OnShelf> key = onShelfMap.keySet();
for(OnShelf onShelf : key){
OnShelfBat onShelfBat = onShelfMap.get(onShelf);
SendEmergencyThread newSendThread = new SendEmergencyThread(onShelf, onShelfBat, false);
executorService.execute(newSendThread);
sendList.add(newSendThread);
}
shutDown();
//thread wait
try{
boolean loop = true;
do{
loop = !executorService.awaitTermination(2, TimeUnit.SECONDS);
}while (loop);
} catch (Exception e) {
e.printStackTrace();
}
}