`
Tristan_S
  • 浏览: 362325 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Callable

 
阅读更多
有返回值, 能使项目更清楚

ExecutorService Callable CompletionService 的关系
参考  http://blog.csdn.net/yanhandle/article/details/9037401

public List<StatisticErrorBean> statisticAllProducerLog(
			final String reportS, final String[] urls) throws IOException,
			ParseException, InterruptedException, ExecutionException {

		List<StatisticErrorBean> resultList = new ArrayList<StatisticErrorBean>();
		final String mainFolder = "/opt/sasuapps/itrc/logs";

		// use multi thread to filter/download/parser log
		ExecutorService es = Executors.newFixedThreadPool(10);
		CompletionService<List<StatisticErrorBean>> cs = new ExecutorCompletionService<List<StatisticErrorBean>>(
				es);

		for (final String url : urls) {
			cs.submit(new ProducerErrorFuture(url, client, mainFolder, reportS,
					this));
		}

		for (int i = 0; i < urls.length; i++) {
			List<StatisticErrorBean> list = cs.take().get();
			combineList(resultList, list);

		}
		es.shutdown();

		return resultList;
	}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics