-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTryJP.java
More file actions
51 lines (49 loc) · 1.35 KB
/
TryJP.java
File metadata and controls
51 lines (49 loc) · 1.35 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
class PrintingJP {
public void java() throws InterruptedException {
synchronized (this) {
while (true) {
System.out.print("Java ");
wait();
notify();
}
}
}
public void programming() throws InterruptedException {
synchronized (this) {
while (true) {
System.out.println("Programming");
notify();
wait();
}
}
}
}
public class TryJP {
public static void main(String[] args) throws InterruptedException {
final PrintingJP obj = new PrintingJP();
Thread t1 = new Thread(new Runnable() {
@Override
public void run() {
try {
obj.java();
} catch (InterruptedException e) {
System.out.println("Exiting Java thread.");
}
}
});
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
try {
obj.programming();
} catch (InterruptedException e) {
System.out.println("Exiting Programming thread.");
}
}
});
t1.start();
t2.start();
// t1.join();
// t2.join();
}
}