-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJoinThreadExample.java
More file actions
41 lines (34 loc) · 932 Bytes
/
JoinThreadExample.java
File metadata and controls
41 lines (34 loc) · 932 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
40
41
package example.ThreadExample;
public class JoinThreadExample {
public static void main(String[] args) {
Threadjoin tj1 = new Threadjoin("task 1");
Threadjoin tj2 = new Threadjoin("task 2");
Threadjoin tj3 = new Threadjoin("task 3");
Threadjoin tj4 = new Threadjoin("task 4");
tj1.start();
tj4.start();
try {
tj1.join();
tj4.join();
} catch (Exception e) {
System.out.println(e);
}
tj2.start();
tj3.start();
}
}
class Threadjoin extends Thread {
Threadjoin(String name) {
super(name);
}
public void run() {
for (int i=0; i<=5; i++) {
try {
sleep(500);
} catch (Exception e) {
System.out.println(e);
}
System.out.println(this.getName() + " is running : " + i);
}
}
}