-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignment7.java
More file actions
66 lines (59 loc) · 1.93 KB
/
assignment7.java
File metadata and controls
66 lines (59 loc) · 1.93 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//Java code for thread creation by extending the Thread class
// class MultithreadingDemo extends Thread {
// public void run() {
// try {
// // Displaying the thread that is running
// System.out.println("Thread " + Thread.currentThread() + " is running");
// } catch (Exception e) {
// System.out.println("Exception is caught");
// }
// }
// }
// // main class
// public class assignment7 {
// public static void main(String args[]) {
// int n = 8;
// for (int i = 0; i < n; i++) {
// MultithreadingDemo object = new MultithreadingDemo();
// object.start();
// }
// }
// }
// class MultithreadingDemo1
// implements Runnable {
// public void run() {
// try {
// // Displaying the thread that is running
// System.out.println("Thread " +
// Thread.currentThread() + " is running");
// } catch (Exception e) {
// // Throwing an exception
// System.out.println("Exception is caught");
// }
// }
// }
// // main Class
// class assignment7 {
// public static void main(String[] args) {
// int n = 8; // Number of Threads
// for (int i = 0; i < n; i++) {
// Thread object = new Thread(new MultithreadingDemo1());
// object.start();
// }
// }
// }
class assignment7 extends Thread {
public void run() {
try {
Thread.sleep(300);
System.out.println("is run() method isAlive " + Thread.currentThread().isAlive());
} catch (InterruptedException ie) {
}
}
public static void main(String[] args) {
assignment7 t1 = new assignment7();
System.out.println("before starting thread isAlive: " + t1.isAlive());
t1.start();
System.out.println("after starting thread isAlive: " + t1.isAlive());
}
}