-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion52.java
More file actions
37 lines (35 loc) · 822 Bytes
/
Question52.java
File metadata and controls
37 lines (35 loc) · 822 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
// program to demonstrate use of isAlive () method
class Count extends Thread {
Count () {
super ("My thread");
System.out.println (this);
start ();
}
public void run () {
try {
for (int i = 0; i < 10; i++) {
System.out.println (i);
Thread.sleep (1000);
}
}
catch (InterruptedException ie) {
System.out.println ("Thread interrupted!");
}
System.out.println ("My thread run() is over!");
}
}
public class Question52 {
public static void main (String[] args) {
Count obj = new Count ();
try {
while (obj.isAlive ()) {
System.out.println ("Main thread alive till child thread is alive.");
Thread.sleep (1500);
}
}
catch (InterruptedException ie) {
System.out.println ("Main thread Interrupted!.");
}
System.out.println ("Main thread run() is over.");
}
}