多线程 : 使用 CompletionService 多线程返回结果
来源:互联网 发布:红五图库永久域名 编辑:程序博客网 时间:2024/06/05 09:12
import java.util.Random;import java.util.concurrent.Callable;import java.util.concurrent.CompletionService;import java.util.concurrent.ExecutionException;import java.util.concurrent.ExecutorCompletionService;import java.util.concurrent.ExecutorService;import java.util.concurrent.Executors;public class CompleteServiceTest {public static void main(String[] args) {ExecutorService threadPool = Executors.newFixedThreadPool(3);CompletionService<Integer> completionService = new ExecutorCompletionService<Integer>(threadPool);for (int i = 0; i < 3; i++) {final int seq = i;completionService.submit(new Callable<Integer>() {@Overridepublic Integer call() throws Exception {Thread.sleep(new Random().nextInt(5000));return seq;}});}for (int i = 0; i < 3; i++) {try {int result = completionService.take().get();System.out.println(result);} catch (InterruptedException | ExecutionException e) {e.printStackTrace();}}}}
1 0
- 多线程 : 使用 CompletionService 多线程返回结果
- 使用CompletionService获取多线程返回值
- Java:多线程,线程池,使用CompletionService通过Future来处理Callable的返回结果
- Java:多线程,线程池,使用CompletionService通过Future来处理Callable的返回结果
- 多线程之CompletionService使用
- 多线程-CompletionService
- Java多线程--CompletionService的使用
- CompletionService 创建多线程,并返回全部线程处理结束后的结果
- 多线程 : 使用 Future 获取线程返回结果
- JAVA多线程—CompletionService的使用介绍
- 多线程,线程池,使用CompletionService通过Future来处理Callable的返回
- 多线程Demo-CompletionService收集线程池执行结果
- 多线程获取线程返回值---Future And CompletionService
- 多线程获取线程返回值---Future And CompletionService
- Java多线程-CompletionService
- java多线程中的CompletionService
- 多线程信号返回测试结果
- java多线程返回函数结果
- CodeForces 631A--Interview
- Weekly roundup: TOEFL
- C#要点与注意
- MFC 数据库ODBC
- 《leetCode》:Basic Calculator
- 多线程 : 使用 CompletionService 多线程返回结果
- 程序员7大软技能测验 你得几分?
- A1111. Online Map (30)
- 百万级访问量网站的技术准备工作(转)
- Ajax工作原理
- stl之关联容器——set,map,hashtable
- CDN缓存服务器现状,squid、nginx、trafficserver、ATS性能测试
- select,poll,epoll区别
- 292. Nim Game