Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Couple {
- String a;
- String b;
- public Couple() {
- a=null;
- b=null;
- }
- public class Couple {
- String a;
- String b;
- public Couple() {
- a=null;
- b=null;
- }
- public void setA(String v) {
- synchronized(a) {
- while(a!=null)
- try {
- wait();
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- a=v;
- this.notifyAll();
- }
- }
- public void setB(String v) {
- synchronized(b) {
- while(b!=null)
- try {
- wait();
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- b=v;
- this.notifyAll();
- }
- }
- public String getA() {
- synchronized(a) {
- while(a==null)
- try {
- wait();
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- String result = a;
- a = null;
- this.notifyAll();
- return result;
- }
- }
- public String getB() {
- synchronized(b) {
- while(b==null)
- try {
- wait();
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- String result = b;
- b = null;
- this.notifyAll();
- return result;
- }
- }
Add Comment
Please, Sign In to add comment