1 13 14 package EDU.oswego.cs.dl.util.concurrent; 15 16 22 23 public class WaitableShort extends SynchronizedShort { 24 28 public WaitableShort(short initialValue) { 29 super(initialValue); 30 } 31 32 36 public WaitableShort(short initialValue, Object lock) { 37 super(initialValue, lock); 38 } 39 40 41 public short set(short newValue) { 42 synchronized (lock_) { 43 lock_.notifyAll(); 44 return super.set(newValue); 45 } 46 } 47 48 public boolean commit(short assumedValue, short newValue) { 49 synchronized (lock_) { 50 boolean success = super.commit(assumedValue, newValue); 51 if (success) lock_.notifyAll(); 52 return success; 53 } 54 } 55 56 public short increment() { 57 synchronized (lock_) { 58 lock_.notifyAll(); 59 return super.increment(); 60 } 61 } 62 63 public short decrement() { 64 synchronized (lock_) { 65 lock_.notifyAll(); 66 return super.decrement(); 67 } 68 } 69 70 public short add(short amount) { 71 synchronized (lock_) { 72 lock_.notifyAll(); 73 return super.add(amount); 74 } 75 } 76 77 public short subtract(short amount) { 78 synchronized (lock_) { 79 lock_.notifyAll(); 80 return super.subtract(amount); 81 } 82 } 83 84 public short multiply(short factor) { 85 synchronized (lock_) { 86 lock_.notifyAll(); 87 return super.multiply(factor); 88 } 89 } 90 91 public short divide(short factor) { 92 synchronized (lock_) { 93 lock_.notifyAll(); 94 return super.divide(factor); 95 } 96 } 97 98 99 103 104 public void whenEqual(short c, Runnable action) throws InterruptedException { 105 synchronized(lock_) { 106 while (!(value_ == c)) lock_.wait(); 107 if (action != null) action.run(); 108 } 109 } 110 111 115 public void whenNotEqual(short c, Runnable action) throws InterruptedException { 116 synchronized (lock_) { 117 while (!(value_ != c)) lock_.wait(); 118 if (action != null) action.run(); 119 } 120 } 121 122 126 public void whenLessEqual(short c, Runnable action) throws InterruptedException { 127 synchronized (lock_) { 128 while (!(value_ <= c)) lock_.wait(); 129 if (action != null) action.run(); 130 } 131 } 132 133 137 public void whenLess(short c, Runnable action) throws InterruptedException { 138 synchronized (lock_) { 139 while (!(value_ < c)) lock_.wait(); 140 if (action != null) action.run(); 141 } 142 } 143 144 148 public void whenGreaterEqual(short c, Runnable action) throws InterruptedException { 149 synchronized (lock_) { 150 while (!(value_ >= c)) lock_.wait(); 151 if (action != null) action.run(); 152 } 153 } 154 155 159 public void whenGreater(short c, Runnable action) throws InterruptedException { 160 synchronized (lock_) { 161 while (!(value_ > c)) lock_.wait(); 162 if (action != null) action.run(); 163 } 164 } 165 166 } 167 168 | Popular Tags |