java ThreadPool判断是否所有任务都完成的方法
2015-09-25 16:38
537 查看
@Test public void test() { ExecutorService threadPool = Executors.newCachedThreadPool(); Future<String> future1 = threadPool.submit(new Callable<String>() { @Override public String call() throws Exception { // TODO Auto-generated method stub for (int i = 0; i < 100000; i++) ; return null; } }); Future<String> future2 = threadPool.submit(new Callable<String>() { @Override public String call() throws Exception { // TODO Auto-generated method stub for (int i = 0; i < 100000; i++) ; return null; } }); // 停止加入新线程 threadPool.shutdown(); // 当任务1和任务2都完成之后,才算完成. while (!(future1.isDone() && future2.isDone())) { System.out.println("f1:" + future1.isDone()); System.out.println("f2:" + future2.isDone()); } System.out.println("work accomplished"); }
相关文章推荐
- 菜鸟使用SSM框架搭建web服务器实现登录功能(Spring+SpringMVC+Mybatis)
- Java学习笔记【内部类】
- java中sleep和wait的异同
- Java JDBC方式连接Access数据库
- java Static 的使用。
- eclipse中文乱码
- 使用EMMA统计Java代码功能测试覆盖率
- Java之Concurrent(并发)包
- Javaweb 学习笔记之文件上传和下载-01
- java web 编解码
- java.lang.NumberFormatException 错误及解决办法
- java web开发 高并发处理
- test7.11
- maven安装以及eclipse配置maven
- javaweb project create
- spring-3-mvc-hello-world-example
- javaEE__jsp自定义标签
- javaEE__jsp加强
- 我的Java成长之路001
- Java编程【1】Define an interface called IAnimal,return 10 animals filled radndomly 3 kinds of animals