Runnable 博客分类: 基础知识
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
推荐阅读
-
Hadoop YARN中内存的设置 博客分类: 大数据 hadoop
-
xl2tp 备份 博客分类: linuxxl2tp xl2tpvpn
-
centos8通过yum安装nginx 博客分类: 软件安装软件使用 nginx
-
mat增加内存 博客分类: JProfile学习
-
Runnable 博客分类: 基础知识
-
Tomcat日志处理(包括catalina.out切分) 博客分类: WEB tomcatcatalina
-
[转]Druid、BoneCP、DBCP、C3P0等主流数据库对比 博客分类: 基础知识
-
tomcat下域名的配置,ROOT.xml的作用 博客分类: WEB tomcat域名Root.xml
-
Missing artifact com.sun:tools:jar:1.5.0 博客分类: WEB tools.jar
-
cp 命令详解 博客分类: Linux cpcopylinuxcommandos