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

多线程处理

 
阅读更多
	ExecutorService threadPool = Executors.newFixedThreadPool(1);
		CompletionService<Object> completeService = new ExecutorCompletionService<Object>(
				threadPool);
		for (final HttpContentRetriever retriver : httpContentRetrievers) {
			completeService.submit(new Runnable() {

				@Override
				public void run() {
					try {
						performParseAndAggregate(retriver.getInputStream(),
								filePath, startDate, endDate, parserTyper,
								pivotCallback);
					} catch (Exception e) {
						e.printStackTrace();
					}
				}

			}, null);
		}
		for (int i = 0; i < httpContentRetrievers.length; i++) {
			try {
				completeService.take();
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		threadPool.shutdown();
		Iterator<Map<String, Object>> iter = pivotCallback.createView()
				.listAll();
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics