176 |
|
} |
177 |
|
|
178 |
|
/** |
179 |
+ |
* getQueueLength reports number of waiting threads |
180 |
+ |
*/ |
181 |
+ |
public void testGetQueueLength_fair() { |
182 |
+ |
final ReentrantLock lock = new ReentrantLock(true); |
183 |
+ |
Thread t1 = new Thread(new InterruptedLockRunnable(lock)); |
184 |
+ |
Thread t2 = new Thread(new InterruptibleLockRunnable(lock)); |
185 |
+ |
try { |
186 |
+ |
assertEquals(0, lock.getQueueLength()); |
187 |
+ |
lock.lock(); |
188 |
+ |
t1.start(); |
189 |
+ |
Thread.sleep(SHORT_DELAY_MS); |
190 |
+ |
assertEquals(1, lock.getQueueLength()); |
191 |
+ |
t2.start(); |
192 |
+ |
Thread.sleep(SHORT_DELAY_MS); |
193 |
+ |
assertEquals(2, lock.getQueueLength()); |
194 |
+ |
t1.interrupt(); |
195 |
+ |
Thread.sleep(SHORT_DELAY_MS); |
196 |
+ |
assertEquals(1, lock.getQueueLength()); |
197 |
+ |
lock.unlock(); |
198 |
+ |
Thread.sleep(SHORT_DELAY_MS); |
199 |
+ |
assertEquals(0, lock.getQueueLength()); |
200 |
+ |
t1.join(); |
201 |
+ |
t2.join(); |
202 |
+ |
} catch(Exception e){ |
203 |
+ |
unexpectedException(); |
204 |
+ |
} |
205 |
+ |
} |
206 |
+ |
|
207 |
+ |
/** |
208 |
|
* getQueuedThreads includes waiting threads |
209 |
|
*/ |
210 |
|
public void testGetQueuedThreads() { |