Questions tagged «completion-service»

10
我应何时在ExecutorService上使用CompletionService?
我刚刚在此博客文章中找到了CompletionService 。但是,这并没有真正展示CompletionService相对于标准ExecutorService的优势。可以使用任一代码编写相同的代码。那么,什么时候CompletionService有用? 您能否提供简短的代码示例以使其清晰可见?例如,此代码示例仅显示不需要CompletionService的位置(=等同于ExecutorService) ExecutorService taskExecutor = Executors.newCachedThreadPool(); // CompletionService<Long> taskCompletionService = // new ExecutorCompletionService<Long>(taskExecutor); Callable<Long> callable = new Callable<Long>() { @Override public Long call() throws Exception { return 1L; } }; Future<Long> future = // taskCompletionService.submit(callable); taskExecutor.submit(callable); while (!future.isDone()) { // Do some work... System.out.println("Working on something..."); } try { …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.