-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJoinDemo.java
More file actions
27 lines (20 loc) · 742 Bytes
/
JoinDemo.java
File metadata and controls
27 lines (20 loc) · 742 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
package Thread.Day_3;
class JoinThread extends Thread {
public void run() {
System.out.println("Thread started " + getName());
try {
Thread.sleep(5000);
} catch (InterruptedException exception) {
}
System.out.println("Thread Ended " + getName());
}
}
public class JoinDemo extends Thread {
public static void main(String[] args) throws InterruptedException {
System.out.println("Main Thread " + Thread.currentThread().getName());
JoinThread joinThread = new JoinThread();
joinThread.start();
joinThread.join(); // main waits for joinThread to finish
System.out.println("Main thread resumes after finishing of joinThread");
}
}