classQ{intn;booleanvalueSet=true;synchronizedvoidput(intn){if(!valueSet)try{wait();}catch(InterruptedExceptione){System.out.println("Interruptedexceptioncaught.");}this.n...
class Q {
int n;
boolean valueSet=true;
synchronized void put(int n) {
if(!valueSet)
try{
wait();
}catch(InterruptedException e){
System.out.println("Interrupted exception caught.");
}
this.n = n;
System.out.println("Put: " + n);
valueSet=false;
notify();
}
synchronized int get() {
if(valueSet)
try{
wait();
}catch(InterruptedException e){
System.out.println("Interrupted exception caught.");
}
System.out.println("Got: " + n);
valueSet=true;
<