- import java.util.concurrent.Callable;
- import java.util.concurrent.ExecutionException;
- import java.util.concurrent.ExecutorService;
- import java.util.concurrent.Executors;
- import java.util.concurrent.Future;
- public class Test {
- public static void main(String[] args) throws InterruptedException, ExecutionException {
- ExecutorService es = Executors.newFixedThreadPool(10);
- int num = 1;
- for(int x = 0;x<9;x++){
- Future<Integer> f = es.submit(new TreadPoolDemo(num));
- num = f.get();
- System.out.println();
- }
- es.shutdown();
- }
- }
- class TreadPoolDemo implements Callable<Integer>{
- private int num;
- public TreadPoolDemo(int num){
- this.num = num;
- }
- public Integer call() throws Exception {
- for(int x = 1;x<=num;x++){
- System.out.print(x+"*"+num+"="+(x*num)+"\t");
- }
- num++;
- return num;
- }
- }
复制代码 |
|