public Map myTrainListDatasTotalCount(HttpServletRequest request) {
Map attributes = new HashMap();
BaseInfoEntity baseInfo = this.getBaseInfo(request);
//通过多个线程并查询
ExecutorService service = Executors.newFixedThreadPool(3); //创建线程池
BlockingQueue> queue = new LinkedBlockingQueue>(); //创建队列
Future future = service.submit(this.getWholeMyTrainListCount(baseInfo,null,"all"));
queue.add(future);
Future future1 = service.submit(this.getWholeMyTrainListCount(baseInfo,null,"wait"));
queue.add(future1);
Future future2 = service.submit(this.getWholeMyTrainListCount(baseInfo,null,"complete"));
queue.add(future2);
int queueSize = queue.size();
for (int i = 0; i < queueSize; i++) {
try {
String[] str = queue.take().get();
//结果处理过程
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
service.shutdown();
return attributes;
}
public Callable getWholeMyTrainListCount(final BaseInfoEntity baseInfo,final WeixPageBean weixPageBean,final String type) { //传递的参数都需要使用final修饰
Callable callable = new Callable() {
public String[] call() throws Exception {
String[] str = new String[2];
//处理过程
return str;
}
};
return callable;
}