-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResource.java
More file actions
40 lines (32 loc) · 752 Bytes
/
Copy pathResource.java
File metadata and controls
40 lines (32 loc) · 752 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
38
39
40
package thread.producer.consumer.test;
public class Resource {
private int content;
boolean isContentFull = false;
public synchronized void put(int content){
if(isContentFull){
try {
wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
this.content = content;
System.out.println("value produced is : " + this.content);
isContentFull = true;
notifyAll();
}
public synchronized void get(){
if(!isContentFull){
try {
wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.out.println("value consumed is : " + this.content);
isContentFull = false;
notifyAll();
}
}