ExecutorService pool = null;
if(sheetList.size() == 1){
pool = Executors.newSingleThreadExecutor();
}else if(sheetList.size() > 1){
temp = "批量";
pool = Executors.newFixedThreadPool(3);
}
StringBuffer sb = new StringBuffer("");
ArrayList<Future<String>> results = new ArrayList<Future<String>>();
try {
for(int i=0;i<sheetList.size();i++){
Map<String,String> sheetMap = sheetList.get(i);
if(orgId == null || docId == null){
orgId = sheetMap.get("orgId");
docId = sheetMap.get("docId");
}
String filePath = sheetMap.get("filePath");
results.add((Future<String>)pool.submit(new CheckSheetUtil(sheetMap,filePath)));
}
boolean b = false;
for(Future<String> fs : results){
try{
if(!fs.get().contains("审核成功")){
b = true;
sb.append(fs.get()+",");//可以调用很多方法,包括是否工作等等
sb.deleteCharAt(sb.lastIndexOf(","));
}
}catch(Exception e){
e.printStackTrace();
}
}
if(!b){
sb.append(temp).append("审核成功!");
}
result = "{success:'true',msg:'"+sb.toString()+"'}";
} catch (Exception e) {
e.printStackTrace();
result = "{success:'false',msg:'审核过程中发生异常!审核失败!'}";
} finally {
pool.shutdown();
updateTotalStatus(orgId+docId);
}
public class CheckSheetUtil implements Callable<String>{
public String call() throws Exception {
return ReadExcelByThread(sheetMap, filePath); //略。。。
}
}