A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 黑夜中那颗星 中级黑马   /  2015-11-12 15:20  /  704 人查看  /  9 人回复  /   1 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. import java.util.concurrent.Callable;
  2. import java.util.concurrent.ExecutionException;
  3. import java.util.concurrent.ExecutorService;
  4. import java.util.concurrent.Executors;
  5. import java.util.concurrent.Future;
  6. public class Test {
  7.         public static void main(String[] args) throws InterruptedException, ExecutionException {
  8.                 ExecutorService es = Executors.newFixedThreadPool(10);
  9.                 int num = 1;
  10.                 for(int x = 0;x<9;x++){
  11.                         Future<Integer> f = es.submit(new TreadPoolDemo(num));
  12.                         num = f.get();
  13.                         System.out.println();
  14.                 }
  15.                 es.shutdown();
  16.         }
  17. }
  18. class TreadPoolDemo implements Callable<Integer>{
  19.         private int num;
  20.         public TreadPoolDemo(int num){
  21.                 this.num = num;
  22.         }
  23.         public Integer call() throws Exception {
  24.                 for(int x = 1;x<=num;x++){
  25.                         System.out.print(x+"*"+num+"="+(x*num)+"\t");
  26.                 }
  27.                 num++;
  28.                 return num;
  29.         }
  30. }
复制代码

9 个回复

倒序浏览
虽然代码有点复杂,从中又看到了很多没有使用过的类和方法,谢谢
回复 使用道具 举报
学习了非常感谢
回复 使用道具 举报
马了,顶起
回复 使用道具 举报
学习了。。。。。。。。
回复 使用道具 举报
好高端的样子,刚刚学的Java,表示看不懂
回复 使用道具 举报
...很多都没见过....
回复 使用道具 举报
零尘 初级黑马 2015-11-12 23:10:52
8#
get顶一个
回复 使用道具 举报
高大上  学习了 ,,,3Q
回复 使用道具 举报
学习一下~~
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马