使用线程池读excel中的多个SHEET


 

		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); //略。。。
 	}
}



 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值