forked from learning-zone/java-basics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJoinMethod.java
More file actions
39 lines (33 loc) · 834 Bytes
/
JoinMethod.java
File metadata and controls
39 lines (33 loc) · 834 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
36
37
38
39
package multithreading;
import java.io.*;
public class JoinMethod extends Thread {
@Override
public void run() {
for(int i = 0; i < 5; i++) {
try {
Thread.sleep(500);
System.out.println("Thread Start: " + Thread.currentThread().getName());
} catch (Exception e) {
System.out.println("Exception: " + e);
}
}
}
public static void main(String[] args) {
JoinMethod t1 = new JoinMethod();
JoinMethod t2 = new JoinMethod();
t1.start();
try {
System.out.println("Thread Ends: " + Thread.currentThread().getName());
t1.join();
} catch (Exception e) {
System.out.println("Exception: " + e);
}
t2.start();
try {
System.out.println("Thread Ends: " + Thread.currentThread().getName());
t2.join();
} catch (Exception e) {
System.out.println("Exception: " + e);
}
}
}