-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathThread status
More file actions
49 lines (39 loc) · 1.01 KB
/
Copy pathThread status
File metadata and controls
49 lines (39 loc) · 1.01 KB
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
42
43
44
45
46
47
48
49
// Java program to Illustrate isAlive() Method
// of Thread class
// Main class extending Thread class
public class oneThread extends Thread {
// Method 1
// run() method for thread
public void run()
{
// Print statement
System.out.println("Apurv ");
// Try block to check for exceptions
try {
// making thread to sleep for 300 nano-seconds
// using sleep() method
Thread.sleep(300);
}
// Catch block to handle InterruptedException
catch (InterruptedException ie) {
}
// Display message when exception occurred
System.out.println("forApurv ");
}
// Method 2
// Main driver method
public static void main(String[] args)
{
// Creating threads using above class as
// it is extending Thread class
oneThread c1 = new oneThread();
oneThread c2 = new oneThread();
// Starting threads
c1.start();
c2.start();
// Checking whether thread is alive or not
// Returning boolean true if alive else false
System.out.println(c1.isAlive());
System.out.println(c2.isAlive());
}
}