14 |
|
|
15 |
|
public class ReentrantLockTest extends JSR166TestCase { |
16 |
|
public static void main(String[] args) { |
17 |
< |
junit.textui.TestRunner.run (suite()); |
17 |
> |
junit.textui.TestRunner.run (suite()); |
18 |
|
} |
19 |
|
public static Test suite() { |
20 |
< |
return new TestSuite(ReentrantLockTest.class); |
20 |
> |
return new TestSuite(ReentrantLockTest.class); |
21 |
|
} |
22 |
|
|
23 |
|
/** |
72 |
|
* locking an unlocked lock succeeds |
73 |
|
*/ |
74 |
|
public void testLock() { |
75 |
< |
ReentrantLock rl = new ReentrantLock(); |
75 |
> |
ReentrantLock rl = new ReentrantLock(); |
76 |
|
rl.lock(); |
77 |
|
assertTrue(rl.isLocked()); |
78 |
|
rl.unlock(); |
83 |
|
* locking an unlocked fair lock succeeds |
84 |
|
*/ |
85 |
|
public void testFairLock() { |
86 |
< |
ReentrantLock rl = new ReentrantLock(true); |
86 |
> |
ReentrantLock rl = new ReentrantLock(true); |
87 |
|
rl.lock(); |
88 |
|
assertTrue(rl.isLocked()); |
89 |
|
rl.unlock(); |
93 |
|
* Unlocking an unlocked lock throws IllegalMonitorStateException |
94 |
|
*/ |
95 |
|
public void testUnlock_IllegalMonitorStateException() { |
96 |
< |
ReentrantLock rl = new ReentrantLock(); |
97 |
< |
try { |
98 |
< |
rl.unlock(); |
99 |
< |
shouldThrow(); |
100 |
< |
} catch (IllegalMonitorStateException success) {} |
96 |
> |
ReentrantLock rl = new ReentrantLock(); |
97 |
> |
try { |
98 |
> |
rl.unlock(); |
99 |
> |
shouldThrow(); |
100 |
> |
} catch (IllegalMonitorStateException success) {} |
101 |
|
} |
102 |
|
|
103 |
|
/** |
104 |
|
* tryLock on an unlocked lock succeeds |
105 |
|
*/ |
106 |
|
public void testTryLock() { |
107 |
< |
ReentrantLock rl = new ReentrantLock(); |
107 |
> |
ReentrantLock rl = new ReentrantLock(); |
108 |
|
assertTrue(rl.tryLock()); |
109 |
|
assertTrue(rl.isLocked()); |
110 |
|
rl.unlock(); |
115 |
|
* hasQueuedThreads reports whether there are waiting threads |
116 |
|
*/ |
117 |
|
public void testhasQueuedThreads() throws InterruptedException { |
118 |
< |
final ReentrantLock lock = new ReentrantLock(); |
118 |
> |
final ReentrantLock lock = new ReentrantLock(); |
119 |
|
Thread t1 = new Thread(new InterruptedLockRunnable(lock)); |
120 |
|
Thread t2 = new Thread(new InterruptibleLockRunnable(lock)); |
121 |
|
assertFalse(lock.hasQueuedThreads()); |
140 |
|
* getQueueLength reports number of waiting threads |
141 |
|
*/ |
142 |
|
public void testGetQueueLength() throws InterruptedException { |
143 |
< |
final ReentrantLock lock = new ReentrantLock(); |
143 |
> |
final ReentrantLock lock = new ReentrantLock(); |
144 |
|
Thread t1 = new Thread(new InterruptedLockRunnable(lock)); |
145 |
|
Thread t2 = new Thread(new InterruptibleLockRunnable(lock)); |
146 |
|
assertEquals(0, lock.getQueueLength()); |
165 |
|
* getQueueLength reports number of waiting threads |
166 |
|
*/ |
167 |
|
public void testGetQueueLength_fair() throws InterruptedException { |
168 |
< |
final ReentrantLock lock = new ReentrantLock(true); |
168 |
> |
final ReentrantLock lock = new ReentrantLock(true); |
169 |
|
Thread t1 = new Thread(new InterruptedLockRunnable(lock)); |
170 |
|
Thread t2 = new Thread(new InterruptibleLockRunnable(lock)); |
171 |
|
assertEquals(0, lock.getQueueLength()); |
190 |
|
* hasQueuedThread(null) throws NPE |
191 |
|
*/ |
192 |
|
public void testHasQueuedThreadNPE() { |
193 |
< |
final ReentrantLock sync = new ReentrantLock(); |
193 |
> |
final ReentrantLock sync = new ReentrantLock(); |
194 |
|
try { |
195 |
|
sync.hasQueuedThread(null); |
196 |
|
shouldThrow(); |
201 |
|
* hasQueuedThread reports whether a thread is queued. |
202 |
|
*/ |
203 |
|
public void testHasQueuedThread() throws InterruptedException { |
204 |
< |
final ReentrantLock sync = new ReentrantLock(); |
204 |
> |
final ReentrantLock sync = new ReentrantLock(); |
205 |
|
Thread t1 = new Thread(new InterruptedLockRunnable(sync)); |
206 |
|
Thread t2 = new Thread(new InterruptibleLockRunnable(sync)); |
207 |
|
assertFalse(sync.hasQueuedThread(t1)); |
232 |
|
* getQueuedThreads includes waiting threads |
233 |
|
*/ |
234 |
|
public void testGetQueuedThreads() throws InterruptedException { |
235 |
< |
final PublicReentrantLock lock = new PublicReentrantLock(); |
235 |
> |
final PublicReentrantLock lock = new PublicReentrantLock(); |
236 |
|
Thread t1 = new Thread(new InterruptedLockRunnable(lock)); |
237 |
|
Thread t2 = new Thread(new InterruptibleLockRunnable(lock)); |
238 |
|
assertTrue(lock.getQueuedThreads().isEmpty()); |
261 |
|
* timed tryLock is interruptible. |
262 |
|
*/ |
263 |
|
public void testInterruptedException2() throws InterruptedException { |
264 |
< |
final ReentrantLock lock = new ReentrantLock(); |
265 |
< |
lock.lock(); |
266 |
< |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
264 |
> |
final ReentrantLock lock = new ReentrantLock(); |
265 |
> |
lock.lock(); |
266 |
> |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
267 |
|
public void realRun() throws InterruptedException { |
268 |
|
lock.tryLock(MEDIUM_DELAY_MS,TimeUnit.MILLISECONDS); |
269 |
|
}}); |
278 |
|
* TryLock on a locked lock fails |
279 |
|
*/ |
280 |
|
public void testTryLockWhenLocked() throws InterruptedException { |
281 |
< |
final ReentrantLock lock = new ReentrantLock(); |
282 |
< |
lock.lock(); |
283 |
< |
Thread t = new Thread(new CheckedRunnable() { |
281 |
> |
final ReentrantLock lock = new ReentrantLock(); |
282 |
> |
lock.lock(); |
283 |
> |
Thread t = new Thread(new CheckedRunnable() { |
284 |
|
public void realRun() { |
285 |
|
threadAssertFalse(lock.tryLock()); |
286 |
|
}}); |
294 |
|
* Timed tryLock on a locked lock times out |
295 |
|
*/ |
296 |
|
public void testTryLock_Timeout() throws InterruptedException { |
297 |
< |
final ReentrantLock lock = new ReentrantLock(); |
298 |
< |
lock.lock(); |
299 |
< |
Thread t = new Thread(new CheckedRunnable() { |
297 |
> |
final ReentrantLock lock = new ReentrantLock(); |
298 |
> |
lock.lock(); |
299 |
> |
Thread t = new Thread(new CheckedRunnable() { |
300 |
|
public void realRun() throws InterruptedException { |
301 |
|
threadAssertFalse(lock.tryLock(1, TimeUnit.MILLISECONDS)); |
302 |
|
}}); |
310 |
|
* getHoldCount returns number of recursive holds |
311 |
|
*/ |
312 |
|
public void testGetHoldCount() { |
313 |
< |
ReentrantLock lock = new ReentrantLock(); |
314 |
< |
for (int i = 1; i <= SIZE; i++) { |
315 |
< |
lock.lock(); |
316 |
< |
assertEquals(i, lock.getHoldCount()); |
317 |
< |
} |
318 |
< |
for (int i = SIZE; i > 0; i--) { |
319 |
< |
lock.unlock(); |
320 |
< |
assertEquals(i-1, lock.getHoldCount()); |
321 |
< |
} |
313 |
> |
ReentrantLock lock = new ReentrantLock(); |
314 |
> |
for (int i = 1; i <= SIZE; i++) { |
315 |
> |
lock.lock(); |
316 |
> |
assertEquals(i, lock.getHoldCount()); |
317 |
> |
} |
318 |
> |
for (int i = SIZE; i > 0; i--) { |
319 |
> |
lock.unlock(); |
320 |
> |
assertEquals(i-1, lock.getHoldCount()); |
321 |
> |
} |
322 |
|
} |
323 |
|
|
324 |
|
|
326 |
|
* isLocked is true when locked and false when not |
327 |
|
*/ |
328 |
|
public void testIsLocked() throws InterruptedException { |
329 |
< |
final ReentrantLock lock = new ReentrantLock(); |
330 |
< |
lock.lock(); |
331 |
< |
assertTrue(lock.isLocked()); |
332 |
< |
lock.unlock(); |
333 |
< |
assertFalse(lock.isLocked()); |
334 |
< |
Thread t = new Thread(new CheckedRunnable() { |
329 |
> |
final ReentrantLock lock = new ReentrantLock(); |
330 |
> |
lock.lock(); |
331 |
> |
assertTrue(lock.isLocked()); |
332 |
> |
lock.unlock(); |
333 |
> |
assertFalse(lock.isLocked()); |
334 |
> |
Thread t = new Thread(new CheckedRunnable() { |
335 |
|
public void realRun() throws InterruptedException { |
336 |
|
lock.lock(); |
337 |
|
Thread.sleep(SMALL_DELAY_MS); |
350 |
|
* lockInterruptibly is interruptible. |
351 |
|
*/ |
352 |
|
public void testLockInterruptibly1() throws InterruptedException { |
353 |
< |
final ReentrantLock lock = new ReentrantLock(); |
354 |
< |
lock.lock(); |
355 |
< |
Thread t = new Thread(new InterruptedLockRunnable(lock)); |
353 |
> |
final ReentrantLock lock = new ReentrantLock(); |
354 |
> |
lock.lock(); |
355 |
> |
Thread t = new Thread(new InterruptedLockRunnable(lock)); |
356 |
|
t.start(); |
357 |
|
Thread.sleep(SHORT_DELAY_MS); |
358 |
|
t.interrupt(); |
365 |
|
* lockInterruptibly succeeds when unlocked, else is interruptible |
366 |
|
*/ |
367 |
|
public void testLockInterruptibly2() throws InterruptedException { |
368 |
< |
final ReentrantLock lock = new ReentrantLock(); |
368 |
> |
final ReentrantLock lock = new ReentrantLock(); |
369 |
|
lock.lockInterruptibly(); |
370 |
< |
Thread t = new Thread(new InterruptedLockRunnable(lock)); |
370 |
> |
Thread t = new Thread(new InterruptedLockRunnable(lock)); |
371 |
|
t.start(); |
372 |
|
t.interrupt(); |
373 |
|
assertTrue(lock.isLocked()); |
379 |
|
* Calling await without holding lock throws IllegalMonitorStateException |
380 |
|
*/ |
381 |
|
public void testAwait_IllegalMonitor() throws InterruptedException { |
382 |
< |
final ReentrantLock lock = new ReentrantLock(); |
382 |
> |
final ReentrantLock lock = new ReentrantLock(); |
383 |
|
final Condition c = lock.newCondition(); |
384 |
|
try { |
385 |
|
c.await(); |
391 |
|
* Calling signal without holding lock throws IllegalMonitorStateException |
392 |
|
*/ |
393 |
|
public void testSignal_IllegalMonitor() { |
394 |
< |
final ReentrantLock lock = new ReentrantLock(); |
394 |
> |
final ReentrantLock lock = new ReentrantLock(); |
395 |
|
final Condition c = lock.newCondition(); |
396 |
|
try { |
397 |
|
c.signal(); |
403 |
|
* awaitNanos without a signal times out |
404 |
|
*/ |
405 |
|
public void testAwaitNanos_Timeout() throws InterruptedException { |
406 |
< |
final ReentrantLock lock = new ReentrantLock(); |
406 |
> |
final ReentrantLock lock = new ReentrantLock(); |
407 |
|
final Condition c = lock.newCondition(); |
408 |
|
lock.lock(); |
409 |
|
long t = c.awaitNanos(100); |
415 |
|
* timed await without a signal times out |
416 |
|
*/ |
417 |
|
public void testAwait_Timeout() throws InterruptedException { |
418 |
< |
final ReentrantLock lock = new ReentrantLock(); |
418 |
> |
final ReentrantLock lock = new ReentrantLock(); |
419 |
|
final Condition c = lock.newCondition(); |
420 |
|
lock.lock(); |
421 |
|
assertFalse(c.await(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
426 |
|
* awaitUntil without a signal times out |
427 |
|
*/ |
428 |
|
public void testAwaitUntil_Timeout() throws InterruptedException { |
429 |
< |
final ReentrantLock lock = new ReentrantLock(); |
429 |
> |
final ReentrantLock lock = new ReentrantLock(); |
430 |
|
final Condition c = lock.newCondition(); |
431 |
|
lock.lock(); |
432 |
|
java.util.Date d = new java.util.Date(); |
438 |
|
* await returns when signalled |
439 |
|
*/ |
440 |
|
public void testAwait() throws InterruptedException { |
441 |
< |
final ReentrantLock lock = new ReentrantLock(); |
441 |
> |
final ReentrantLock lock = new ReentrantLock(); |
442 |
|
final Condition c = lock.newCondition(); |
443 |
< |
Thread t = new Thread(new CheckedRunnable() { |
443 |
> |
Thread t = new Thread(new CheckedRunnable() { |
444 |
|
public void realRun() throws InterruptedException { |
445 |
|
lock.lock(); |
446 |
|
c.await(); |
460 |
|
* hasWaiters throws NPE if null |
461 |
|
*/ |
462 |
|
public void testHasWaitersNPE() { |
463 |
< |
final ReentrantLock lock = new ReentrantLock(); |
463 |
> |
final ReentrantLock lock = new ReentrantLock(); |
464 |
|
try { |
465 |
|
lock.hasWaiters(null); |
466 |
|
shouldThrow(); |
471 |
|
* getWaitQueueLength throws NPE if null |
472 |
|
*/ |
473 |
|
public void testGetWaitQueueLengthNPE() { |
474 |
< |
final ReentrantLock lock = new ReentrantLock(); |
474 |
> |
final ReentrantLock lock = new ReentrantLock(); |
475 |
|
try { |
476 |
|
lock.getWaitQueueLength(null); |
477 |
|
shouldThrow(); |
483 |
|
* getWaitingThreads throws NPE if null |
484 |
|
*/ |
485 |
|
public void testGetWaitingThreadsNPE() { |
486 |
< |
final PublicReentrantLock lock = new PublicReentrantLock(); |
486 |
> |
final PublicReentrantLock lock = new PublicReentrantLock(); |
487 |
|
try { |
488 |
|
lock.getWaitingThreads(null); |
489 |
|
shouldThrow(); |
495 |
|
* hasWaiters throws IAE if not owned |
496 |
|
*/ |
497 |
|
public void testHasWaitersIAE() { |
498 |
< |
final ReentrantLock lock = new ReentrantLock(); |
498 |
> |
final ReentrantLock lock = new ReentrantLock(); |
499 |
|
final Condition c = lock.newCondition(); |
500 |
< |
final ReentrantLock lock2 = new ReentrantLock(); |
500 |
> |
final ReentrantLock lock2 = new ReentrantLock(); |
501 |
|
try { |
502 |
|
lock2.hasWaiters(c); |
503 |
|
shouldThrow(); |
508 |
|
* hasWaiters throws IMSE if not locked |
509 |
|
*/ |
510 |
|
public void testHasWaitersIMSE() { |
511 |
< |
final ReentrantLock lock = new ReentrantLock(); |
511 |
> |
final ReentrantLock lock = new ReentrantLock(); |
512 |
|
final Condition c = lock.newCondition(); |
513 |
|
try { |
514 |
|
lock.hasWaiters(c); |
521 |
|
* getWaitQueueLength throws IAE if not owned |
522 |
|
*/ |
523 |
|
public void testGetWaitQueueLengthIAE() { |
524 |
< |
final ReentrantLock lock = new ReentrantLock(); |
524 |
> |
final ReentrantLock lock = new ReentrantLock(); |
525 |
|
final Condition c = lock.newCondition(); |
526 |
< |
final ReentrantLock lock2 = new ReentrantLock(); |
526 |
> |
final ReentrantLock lock2 = new ReentrantLock(); |
527 |
|
try { |
528 |
|
lock2.getWaitQueueLength(c); |
529 |
|
shouldThrow(); |
534 |
|
* getWaitQueueLength throws IMSE if not locked |
535 |
|
*/ |
536 |
|
public void testGetWaitQueueLengthIMSE() { |
537 |
< |
final ReentrantLock lock = new ReentrantLock(); |
537 |
> |
final ReentrantLock lock = new ReentrantLock(); |
538 |
|
final Condition c = lock.newCondition(); |
539 |
|
try { |
540 |
|
lock.getWaitQueueLength(c); |
547 |
|
* getWaitingThreads throws IAE if not owned |
548 |
|
*/ |
549 |
|
public void testGetWaitingThreadsIAE() { |
550 |
< |
final PublicReentrantLock lock = new PublicReentrantLock(); |
550 |
> |
final PublicReentrantLock lock = new PublicReentrantLock(); |
551 |
|
final Condition c = lock.newCondition(); |
552 |
< |
final PublicReentrantLock lock2 = new PublicReentrantLock(); |
552 |
> |
final PublicReentrantLock lock2 = new PublicReentrantLock(); |
553 |
|
try { |
554 |
|
lock2.getWaitingThreads(c); |
555 |
|
shouldThrow(); |
560 |
|
* getWaitingThreads throws IMSE if not locked |
561 |
|
*/ |
562 |
|
public void testGetWaitingThreadsIMSE() { |
563 |
< |
final PublicReentrantLock lock = new PublicReentrantLock(); |
563 |
> |
final PublicReentrantLock lock = new PublicReentrantLock(); |
564 |
|
final Condition c = lock.newCondition(); |
565 |
|
try { |
566 |
|
lock.getWaitingThreads(c); |
573 |
|
* hasWaiters returns true when a thread is waiting, else false |
574 |
|
*/ |
575 |
|
public void testHasWaiters() throws InterruptedException { |
576 |
< |
final ReentrantLock lock = new ReentrantLock(); |
576 |
> |
final ReentrantLock lock = new ReentrantLock(); |
577 |
|
final Condition c = lock.newCondition(); |
578 |
< |
Thread t = new Thread(new CheckedRunnable() { |
578 |
> |
Thread t = new Thread(new CheckedRunnable() { |
579 |
|
public void realRun() throws InterruptedException { |
580 |
|
lock.lock(); |
581 |
|
threadAssertFalse(lock.hasWaiters(c)); |
604 |
|
* getWaitQueueLength returns number of waiting threads |
605 |
|
*/ |
606 |
|
public void testGetWaitQueueLength() throws InterruptedException { |
607 |
< |
final ReentrantLock lock = new ReentrantLock(); |
607 |
> |
final ReentrantLock lock = new ReentrantLock(); |
608 |
|
final Condition c = lock.newCondition(); |
609 |
< |
Thread t1 = new Thread(new CheckedRunnable() { |
609 |
> |
Thread t1 = new Thread(new CheckedRunnable() { |
610 |
|
public void realRun() throws InterruptedException { |
611 |
|
lock.lock(); |
612 |
|
threadAssertFalse(lock.hasWaiters(c)); |
615 |
|
lock.unlock(); |
616 |
|
}}); |
617 |
|
|
618 |
< |
Thread t2 = new Thread(new CheckedRunnable() { |
618 |
> |
Thread t2 = new Thread(new CheckedRunnable() { |
619 |
|
public void realRun() throws InterruptedException { |
620 |
|
lock.lock(); |
621 |
|
threadAssertTrue(lock.hasWaiters(c)); |
648 |
|
* getWaitingThreads returns only and all waiting threads |
649 |
|
*/ |
650 |
|
public void testGetWaitingThreads() throws InterruptedException { |
651 |
< |
final PublicReentrantLock lock = new PublicReentrantLock(); |
651 |
> |
final PublicReentrantLock lock = new PublicReentrantLock(); |
652 |
|
final Condition c = lock.newCondition(); |
653 |
< |
Thread t1 = new Thread(new CheckedRunnable() { |
653 |
> |
Thread t1 = new Thread(new CheckedRunnable() { |
654 |
|
public void realRun() throws InterruptedException { |
655 |
|
lock.lock(); |
656 |
|
threadAssertTrue(lock.getWaitingThreads(c).isEmpty()); |
658 |
|
lock.unlock(); |
659 |
|
}}); |
660 |
|
|
661 |
< |
Thread t2 = new Thread(new CheckedRunnable() { |
661 |
> |
Thread t2 = new Thread(new CheckedRunnable() { |
662 |
|
public void realRun() throws InterruptedException { |
663 |
|
lock.lock(); |
664 |
|
threadAssertFalse(lock.getWaitingThreads(c).isEmpty()); |
749 |
|
* await is interruptible |
750 |
|
*/ |
751 |
|
public void testAwait_Interrupt() throws InterruptedException { |
752 |
< |
final ReentrantLock lock = new ReentrantLock(); |
752 |
> |
final ReentrantLock lock = new ReentrantLock(); |
753 |
|
final Condition c = lock.newCondition(); |
754 |
< |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
755 |
< |
public void realRun() throws InterruptedException { |
754 |
> |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
755 |
> |
public void realRun() throws InterruptedException { |
756 |
|
lock.lock(); |
757 |
|
c.await(); |
758 |
|
}}); |
768 |
|
* awaitNanos is interruptible |
769 |
|
*/ |
770 |
|
public void testAwaitNanos_Interrupt() throws InterruptedException { |
771 |
< |
final ReentrantLock lock = new ReentrantLock(); |
771 |
> |
final ReentrantLock lock = new ReentrantLock(); |
772 |
|
final Condition c = lock.newCondition(); |
773 |
< |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
774 |
< |
public void realRun() throws InterruptedException { |
773 |
> |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
774 |
> |
public void realRun() throws InterruptedException { |
775 |
|
lock.lock(); |
776 |
|
c.awaitNanos(1000 * 1000 * 1000); // 1 sec |
777 |
|
}}); |
787 |
|
* awaitUntil is interruptible |
788 |
|
*/ |
789 |
|
public void testAwaitUntil_Interrupt() throws InterruptedException { |
790 |
< |
final ReentrantLock lock = new ReentrantLock(); |
790 |
> |
final ReentrantLock lock = new ReentrantLock(); |
791 |
|
final Condition c = lock.newCondition(); |
792 |
< |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
793 |
< |
public void realRun() throws InterruptedException { |
792 |
> |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
793 |
> |
public void realRun() throws InterruptedException { |
794 |
|
lock.lock(); |
795 |
|
java.util.Date d = new java.util.Date(); |
796 |
|
c.awaitUntil(new java.util.Date(d.getTime() + 10000)); |
807 |
|
* signalAll wakes up all threads |
808 |
|
*/ |
809 |
|
public void testSignalAll() throws InterruptedException { |
810 |
< |
final ReentrantLock lock = new ReentrantLock(); |
810 |
> |
final ReentrantLock lock = new ReentrantLock(); |
811 |
|
final Condition c = lock.newCondition(); |
812 |
< |
Thread t1 = new Thread(new CheckedRunnable() { |
812 |
> |
Thread t1 = new Thread(new CheckedRunnable() { |
813 |
|
public void realRun() throws InterruptedException { |
814 |
|
lock.lock(); |
815 |
|
c.await(); |
816 |
|
lock.unlock(); |
817 |
|
}}); |
818 |
|
|
819 |
< |
Thread t2 = new Thread(new CheckedRunnable() { |
819 |
> |
Thread t2 = new Thread(new CheckedRunnable() { |
820 |
|
public void realRun() throws InterruptedException { |
821 |
|
lock.lock(); |
822 |
|
c.await(); |
839 |
|
* await after multiple reentrant locking preserves lock count |
840 |
|
*/ |
841 |
|
public void testAwaitLockCount() throws InterruptedException { |
842 |
< |
final ReentrantLock lock = new ReentrantLock(); |
842 |
> |
final ReentrantLock lock = new ReentrantLock(); |
843 |
|
final Condition c = lock.newCondition(); |
844 |
< |
Thread t1 = new Thread(new CheckedRunnable() { |
844 |
> |
Thread t1 = new Thread(new CheckedRunnable() { |
845 |
|
public void realRun() throws InterruptedException { |
846 |
|
lock.lock(); |
847 |
|
threadAssertEquals(1, lock.getHoldCount()); |
850 |
|
lock.unlock(); |
851 |
|
}}); |
852 |
|
|
853 |
< |
Thread t2 = new Thread(new CheckedRunnable() { |
853 |
> |
Thread t2 = new Thread(new CheckedRunnable() { |
854 |
|
public void realRun() throws InterruptedException { |
855 |
|
lock.lock(); |
856 |
|
lock.lock(); |