Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ss.week7.threads;
- import java.util.concurrent.locks.*;
- public class SynchronizedIntcell implements IntCell {
- private int value = 0;
- private boolean consumed;
- public synchronized void setValue(int valueArg) {
- try{
- while(!consumed){
- wait();
- }
- } catch(Exception e){
- System.out.println(e.getMessage());
- }
- value= valueArg;
- consumed = false;
- notify();
- }
- public synchronized int getValue() {
- try{
- while(consumed){
- wait();
- }
- } catch(Exception e){
- System.out.println(e.getMessage());
- }
- consumed = true;
- notify();
- return value;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement