-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathABC.java
More file actions
49 lines (46 loc) · 1.49 KB
/
Copy pathABC.java
File metadata and controls
49 lines (46 loc) · 1.49 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
public class ABC implements Runnable {
public void run() {
System.out.println("In abc");
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("State of thread t1 inside thread t2 : " + Thread2.t1.getState());
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public class Thread2 {
public static Thread t1;
public static Thread2 obj;
public static void main(String args[]) {
obj = new Thread2();
t1 = new THread(obj);
System.out.println("State of thread T1 after spawning : " + t1.getState());
t1.start();
System.out.println("State of t1 after start() : " + t1.getState());
}
public void run() {
ABC myobj = new ABC();
Thread t2 = new Thread(myObj);
System.out.println("State of t2 after spawning : " + t2.getState());
t2.start();
System.out.println("State of t2 after start : " + t2.getState());
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("State of t2 after sleep() : " + t2.getState());
try {
t2.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("State of t2 after comp exec : " + t2.getState());
}
}