forked from JustinSDK/JavaSE6Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadA.java
More file actions
35 lines (30 loc) · 995 Bytes
/
ThreadA.java
File metadata and controls
35 lines (30 loc) · 995 Bytes
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
package onlyfun.caterpillar;
public class ThreadA {
public static void main(String[] args) {
System.out.println("Thread A 執行");
Thread threadB = new Thread(new Runnable() {
public void run() {
try {
System.out.println("Thread B 開始..");
for(int i = 0; i < 5; i++) {
Thread.sleep(1000);
System.out.println("Thread B 執行..");
}
System.out.println("Thread B 即將結束..");
}
catch(InterruptedException e) {
e.printStackTrace();
}
}
});
threadB.start();
try {
// Thread B 加入 Thread A
threadB.join();
}
catch(InterruptedException e) {
e.printStackTrace();
}
System.out.println("Thread A 執行");
}
}