1 import java.lang.Runnable;
2 import java.lang.Thread;
3 import java.util.concurrent.Executors;
4 import java.util.concurrent.ExecutorService;
5 import java.util.concurrent.Future;
6 import java.util.concurrent.ExecutionException;
7
8 class runclass implements Runnable {
9 public static long id = 0;
10
11 public void run(){
12 ++id;
13 System.out.println(id);
14 }
15 }
16
17 class test {
18 public static void main(String[] args) throws InterruptedException, ExecutionException {
19 ExecutorService exec = Executors.newCachedThreadPool();
20 Future result1 = exec.submit(new runclass());
21 Future result2 = exec.submit(new runclass());
22 while (!result1.isDone() || !result2.isDone()){
23 Thread.sleep(1000);
24 break;
25 }
26 exec.shutdown();
27 }
28 }
29
Runnable
最新推荐文章于 2024-08-12 15:45:48 发布