-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJoinMain.java
More file actions
50 lines (40 loc) · 1.17 KB
/
Copy pathJoinMain.java
File metadata and controls
50 lines (40 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.github.why168;
import java.util.concurrent.TimeUnit;
/**
* Join
*
* @author Edwin.Wu edwin.wu05@gmail.com
* @version 2020/1/12 6:41 下午
* @since JDK1.8
*/
public class JoinMain {
public static void main(String[] args) {
Thread threadA = new Thread(new RunJoin("A"));
Thread threadB = new Thread(new RunJoin("B"));
threadA.start();
threadB.start();
try {
threadA.join();
threadB.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("JoinMain .......");
}
static class RunJoin implements Runnable {
private final String tag;
public RunJoin(String tag) {
this.tag = tag;
}
@Override
public void run() {
System.out.println(Thread.currentThread().getName() + " * " + tag + " -- start");
try {
TimeUnit.SECONDS.sleep(40000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(Thread.currentThread().getName() + " * " + tag + " -- stop");
}
}
}