Guest User

Untitled

a guest
Jan 17th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. public class Couple {
  2. String a;
  3. String b;
  4.  
  5. public Couple() {
  6. a=null;
  7. b=null;
  8. }
  9.  
  10. public class Couple {
  11. String a;
  12. String b;
  13.  
  14. public Couple() {
  15. a=null;
  16. b=null;
  17. }
  18.  
  19. public void setA(String v) {
  20. synchronized(a) {
  21. while(a!=null)
  22. try {
  23. wait();
  24. } catch (InterruptedException e) {
  25. // TODO Auto-generated catch block
  26. e.printStackTrace();
  27. }
  28. a=v;
  29. this.notifyAll();
  30. }
  31. }
  32.  
  33. public void setB(String v) {
  34. synchronized(b) {
  35. while(b!=null)
  36. try {
  37. wait();
  38. } catch (InterruptedException e) {
  39. // TODO Auto-generated catch block
  40. e.printStackTrace();
  41. }
  42. b=v;
  43. this.notifyAll();
  44. }
  45. }
  46.  
  47. public String getA() {
  48. synchronized(a) {
  49. while(a==null)
  50. try {
  51. wait();
  52. } catch (InterruptedException e) {
  53. // TODO Auto-generated catch block
  54. e.printStackTrace();
  55. }
  56. String result = a;
  57. a = null;
  58. this.notifyAll();
  59. return result;
  60. }
  61. }
  62.  
  63. public String getB() {
  64. synchronized(b) {
  65. while(b==null)
  66. try {
  67. wait();
  68. } catch (InterruptedException e) {
  69. // TODO Auto-generated catch block
  70. e.printStackTrace();
  71. }
  72. String result = b;
  73. b = null;
  74. this.notifyAll();
  75. return result;
  76. }
  77. }
Add Comment
Please, Sign In to add comment