9 |
|
import junit.framework.*; |
10 |
|
import java.util.concurrent.locks.*; |
11 |
|
import java.util.concurrent.*; |
12 |
+ |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
13 |
|
import java.util.*; |
14 |
|
import java.io.*; |
15 |
|
|
16 |
|
public class ReentrantLockTest extends JSR166TestCase { |
17 |
|
public static void main(String[] args) { |
18 |
< |
junit.textui.TestRunner.run (suite()); |
18 |
> |
junit.textui.TestRunner.run (suite()); |
19 |
|
} |
20 |
|
public static Test suite() { |
21 |
< |
return new TestSuite(ReentrantLockTest.class); |
21 |
> |
return new TestSuite(ReentrantLockTest.class); |
22 |
|
} |
23 |
|
|
24 |
|
/** |
73 |
|
* locking an unlocked lock succeeds |
74 |
|
*/ |
75 |
|
public void testLock() { |
76 |
< |
ReentrantLock rl = new ReentrantLock(); |
76 |
> |
ReentrantLock rl = new ReentrantLock(); |
77 |
|
rl.lock(); |
78 |
|
assertTrue(rl.isLocked()); |
79 |
|
rl.unlock(); |
84 |
|
* locking an unlocked fair lock succeeds |
85 |
|
*/ |
86 |
|
public void testFairLock() { |
87 |
< |
ReentrantLock rl = new ReentrantLock(true); |
87 |
> |
ReentrantLock rl = new ReentrantLock(true); |
88 |
|
rl.lock(); |
89 |
|
assertTrue(rl.isLocked()); |
90 |
|
rl.unlock(); |
94 |
|
* Unlocking an unlocked lock throws IllegalMonitorStateException |
95 |
|
*/ |
96 |
|
public void testUnlock_IllegalMonitorStateException() { |
97 |
< |
ReentrantLock rl = new ReentrantLock(); |
98 |
< |
try { |
99 |
< |
rl.unlock(); |
100 |
< |
shouldThrow(); |
101 |
< |
} catch (IllegalMonitorStateException success) {} |
97 |
> |
ReentrantLock rl = new ReentrantLock(); |
98 |
> |
try { |
99 |
> |
rl.unlock(); |
100 |
> |
shouldThrow(); |
101 |
> |
} catch (IllegalMonitorStateException success) {} |
102 |
|
} |
103 |
|
|
104 |
|
/** |
105 |
|
* tryLock on an unlocked lock succeeds |
106 |
|
*/ |
107 |
|
public void testTryLock() { |
108 |
< |
ReentrantLock rl = new ReentrantLock(); |
108 |
> |
ReentrantLock rl = new ReentrantLock(); |
109 |
|
assertTrue(rl.tryLock()); |
110 |
|
assertTrue(rl.isLocked()); |
111 |
|
rl.unlock(); |
116 |
|
* hasQueuedThreads reports whether there are waiting threads |
117 |
|
*/ |
118 |
|
public void testhasQueuedThreads() throws InterruptedException { |
119 |
< |
final ReentrantLock lock = new ReentrantLock(); |
119 |
> |
final ReentrantLock lock = new ReentrantLock(); |
120 |
|
Thread t1 = new Thread(new InterruptedLockRunnable(lock)); |
121 |
|
Thread t2 = new Thread(new InterruptibleLockRunnable(lock)); |
122 |
|
assertFalse(lock.hasQueuedThreads()); |
141 |
|
* getQueueLength reports number of waiting threads |
142 |
|
*/ |
143 |
|
public void testGetQueueLength() throws InterruptedException { |
144 |
< |
final ReentrantLock lock = new ReentrantLock(); |
144 |
> |
final ReentrantLock lock = new ReentrantLock(); |
145 |
|
Thread t1 = new Thread(new InterruptedLockRunnable(lock)); |
146 |
|
Thread t2 = new Thread(new InterruptibleLockRunnable(lock)); |
147 |
|
assertEquals(0, lock.getQueueLength()); |
166 |
|
* getQueueLength reports number of waiting threads |
167 |
|
*/ |
168 |
|
public void testGetQueueLength_fair() throws InterruptedException { |
169 |
< |
final ReentrantLock lock = new ReentrantLock(true); |
169 |
> |
final ReentrantLock lock = new ReentrantLock(true); |
170 |
|
Thread t1 = new Thread(new InterruptedLockRunnable(lock)); |
171 |
|
Thread t2 = new Thread(new InterruptibleLockRunnable(lock)); |
172 |
|
assertEquals(0, lock.getQueueLength()); |
191 |
|
* hasQueuedThread(null) throws NPE |
192 |
|
*/ |
193 |
|
public void testHasQueuedThreadNPE() { |
194 |
< |
final ReentrantLock sync = new ReentrantLock(); |
194 |
> |
final ReentrantLock sync = new ReentrantLock(); |
195 |
|
try { |
196 |
|
sync.hasQueuedThread(null); |
197 |
|
shouldThrow(); |
202 |
|
* hasQueuedThread reports whether a thread is queued. |
203 |
|
*/ |
204 |
|
public void testHasQueuedThread() throws InterruptedException { |
205 |
< |
final ReentrantLock sync = new ReentrantLock(); |
205 |
> |
final ReentrantLock sync = new ReentrantLock(); |
206 |
|
Thread t1 = new Thread(new InterruptedLockRunnable(sync)); |
207 |
|
Thread t2 = new Thread(new InterruptibleLockRunnable(sync)); |
208 |
|
assertFalse(sync.hasQueuedThread(t1)); |
233 |
|
* getQueuedThreads includes waiting threads |
234 |
|
*/ |
235 |
|
public void testGetQueuedThreads() throws InterruptedException { |
236 |
< |
final PublicReentrantLock lock = new PublicReentrantLock(); |
236 |
> |
final PublicReentrantLock lock = new PublicReentrantLock(); |
237 |
|
Thread t1 = new Thread(new InterruptedLockRunnable(lock)); |
238 |
|
Thread t2 = new Thread(new InterruptibleLockRunnable(lock)); |
239 |
|
assertTrue(lock.getQueuedThreads().isEmpty()); |
262 |
|
* timed tryLock is interruptible. |
263 |
|
*/ |
264 |
|
public void testInterruptedException2() throws InterruptedException { |
265 |
< |
final ReentrantLock lock = new ReentrantLock(); |
266 |
< |
lock.lock(); |
267 |
< |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
265 |
> |
final ReentrantLock lock = new ReentrantLock(); |
266 |
> |
lock.lock(); |
267 |
> |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
268 |
|
public void realRun() throws InterruptedException { |
269 |
< |
lock.tryLock(MEDIUM_DELAY_MS,TimeUnit.MILLISECONDS); |
269 |
> |
lock.tryLock(MEDIUM_DELAY_MS,MILLISECONDS); |
270 |
|
}}); |
271 |
|
|
272 |
|
t.start(); |
273 |
+ |
Thread.sleep(SHORT_DELAY_MS); |
274 |
|
t.interrupt(); |
275 |
|
t.join(); |
276 |
|
} |
280 |
|
* TryLock on a locked lock fails |
281 |
|
*/ |
282 |
|
public void testTryLockWhenLocked() throws InterruptedException { |
283 |
< |
final ReentrantLock lock = new ReentrantLock(); |
284 |
< |
lock.lock(); |
285 |
< |
Thread t = new Thread(new CheckedRunnable() { |
283 |
> |
final ReentrantLock lock = new ReentrantLock(); |
284 |
> |
lock.lock(); |
285 |
> |
Thread t = new Thread(new CheckedRunnable() { |
286 |
|
public void realRun() { |
287 |
|
threadAssertFalse(lock.tryLock()); |
288 |
|
}}); |
296 |
|
* Timed tryLock on a locked lock times out |
297 |
|
*/ |
298 |
|
public void testTryLock_Timeout() throws InterruptedException { |
299 |
< |
final ReentrantLock lock = new ReentrantLock(); |
300 |
< |
lock.lock(); |
301 |
< |
Thread t = new Thread(new CheckedRunnable() { |
299 |
> |
final ReentrantLock lock = new ReentrantLock(); |
300 |
> |
lock.lock(); |
301 |
> |
Thread t = new Thread(new CheckedRunnable() { |
302 |
|
public void realRun() throws InterruptedException { |
303 |
< |
threadAssertFalse(lock.tryLock(1, TimeUnit.MILLISECONDS)); |
303 |
> |
threadAssertFalse(lock.tryLock(1, MILLISECONDS)); |
304 |
|
}}); |
305 |
|
|
306 |
|
t.start(); |
312 |
|
* getHoldCount returns number of recursive holds |
313 |
|
*/ |
314 |
|
public void testGetHoldCount() { |
315 |
< |
ReentrantLock lock = new ReentrantLock(); |
316 |
< |
for (int i = 1; i <= SIZE; i++) { |
317 |
< |
lock.lock(); |
318 |
< |
assertEquals(i, lock.getHoldCount()); |
319 |
< |
} |
320 |
< |
for (int i = SIZE; i > 0; i--) { |
321 |
< |
lock.unlock(); |
322 |
< |
assertEquals(i-1, lock.getHoldCount()); |
323 |
< |
} |
315 |
> |
ReentrantLock lock = new ReentrantLock(); |
316 |
> |
for (int i = 1; i <= SIZE; i++) { |
317 |
> |
lock.lock(); |
318 |
> |
assertEquals(i, lock.getHoldCount()); |
319 |
> |
} |
320 |
> |
for (int i = SIZE; i > 0; i--) { |
321 |
> |
lock.unlock(); |
322 |
> |
assertEquals(i-1, lock.getHoldCount()); |
323 |
> |
} |
324 |
|
} |
325 |
|
|
326 |
|
|
328 |
|
* isLocked is true when locked and false when not |
329 |
|
*/ |
330 |
|
public void testIsLocked() throws InterruptedException { |
331 |
< |
final ReentrantLock lock = new ReentrantLock(); |
332 |
< |
lock.lock(); |
333 |
< |
assertTrue(lock.isLocked()); |
334 |
< |
lock.unlock(); |
335 |
< |
assertFalse(lock.isLocked()); |
336 |
< |
Thread t = new Thread(new CheckedRunnable() { |
331 |
> |
final ReentrantLock lock = new ReentrantLock(); |
332 |
> |
lock.lock(); |
333 |
> |
assertTrue(lock.isLocked()); |
334 |
> |
lock.unlock(); |
335 |
> |
assertFalse(lock.isLocked()); |
336 |
> |
Thread t = new Thread(new CheckedRunnable() { |
337 |
|
public void realRun() throws InterruptedException { |
338 |
|
lock.lock(); |
339 |
|
Thread.sleep(SMALL_DELAY_MS); |
352 |
|
* lockInterruptibly is interruptible. |
353 |
|
*/ |
354 |
|
public void testLockInterruptibly1() throws InterruptedException { |
355 |
< |
final ReentrantLock lock = new ReentrantLock(); |
356 |
< |
lock.lock(); |
357 |
< |
Thread t = new Thread(new InterruptedLockRunnable(lock)); |
355 |
> |
final ReentrantLock lock = new ReentrantLock(); |
356 |
> |
lock.lock(); |
357 |
> |
Thread t = new Thread(new InterruptedLockRunnable(lock)); |
358 |
|
t.start(); |
359 |
|
Thread.sleep(SHORT_DELAY_MS); |
360 |
|
t.interrupt(); |
367 |
|
* lockInterruptibly succeeds when unlocked, else is interruptible |
368 |
|
*/ |
369 |
|
public void testLockInterruptibly2() throws InterruptedException { |
370 |
< |
final ReentrantLock lock = new ReentrantLock(); |
370 |
> |
final ReentrantLock lock = new ReentrantLock(); |
371 |
|
lock.lockInterruptibly(); |
372 |
< |
Thread t = new Thread(new InterruptedLockRunnable(lock)); |
372 |
> |
Thread t = new Thread(new InterruptedLockRunnable(lock)); |
373 |
|
t.start(); |
374 |
+ |
Thread.sleep(SHORT_DELAY_MS); |
375 |
|
t.interrupt(); |
376 |
|
assertTrue(lock.isLocked()); |
377 |
|
assertTrue(lock.isHeldByCurrentThread()); |
382 |
|
* Calling await without holding lock throws IllegalMonitorStateException |
383 |
|
*/ |
384 |
|
public void testAwait_IllegalMonitor() throws InterruptedException { |
385 |
< |
final ReentrantLock lock = new ReentrantLock(); |
385 |
> |
final ReentrantLock lock = new ReentrantLock(); |
386 |
|
final Condition c = lock.newCondition(); |
387 |
|
try { |
388 |
|
c.await(); |
394 |
|
* Calling signal without holding lock throws IllegalMonitorStateException |
395 |
|
*/ |
396 |
|
public void testSignal_IllegalMonitor() { |
397 |
< |
final ReentrantLock lock = new ReentrantLock(); |
397 |
> |
final ReentrantLock lock = new ReentrantLock(); |
398 |
|
final Condition c = lock.newCondition(); |
399 |
|
try { |
400 |
|
c.signal(); |
406 |
|
* awaitNanos without a signal times out |
407 |
|
*/ |
408 |
|
public void testAwaitNanos_Timeout() throws InterruptedException { |
409 |
< |
final ReentrantLock lock = new ReentrantLock(); |
409 |
> |
final ReentrantLock lock = new ReentrantLock(); |
410 |
|
final Condition c = lock.newCondition(); |
411 |
|
lock.lock(); |
412 |
|
long t = c.awaitNanos(100); |
418 |
|
* timed await without a signal times out |
419 |
|
*/ |
420 |
|
public void testAwait_Timeout() throws InterruptedException { |
421 |
< |
final ReentrantLock lock = new ReentrantLock(); |
421 |
> |
final ReentrantLock lock = new ReentrantLock(); |
422 |
|
final Condition c = lock.newCondition(); |
423 |
|
lock.lock(); |
424 |
< |
assertFalse(c.await(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
424 |
> |
assertFalse(c.await(SHORT_DELAY_MS, MILLISECONDS)); |
425 |
|
lock.unlock(); |
426 |
|
} |
427 |
|
|
429 |
|
* awaitUntil without a signal times out |
430 |
|
*/ |
431 |
|
public void testAwaitUntil_Timeout() throws InterruptedException { |
432 |
< |
final ReentrantLock lock = new ReentrantLock(); |
432 |
> |
final ReentrantLock lock = new ReentrantLock(); |
433 |
|
final Condition c = lock.newCondition(); |
434 |
|
lock.lock(); |
435 |
|
java.util.Date d = new java.util.Date(); |
441 |
|
* await returns when signalled |
442 |
|
*/ |
443 |
|
public void testAwait() throws InterruptedException { |
444 |
< |
final ReentrantLock lock = new ReentrantLock(); |
444 |
> |
final ReentrantLock lock = new ReentrantLock(); |
445 |
|
final Condition c = lock.newCondition(); |
446 |
< |
Thread t = new Thread(new CheckedRunnable() { |
446 |
> |
Thread t = new Thread(new CheckedRunnable() { |
447 |
|
public void realRun() throws InterruptedException { |
448 |
|
lock.lock(); |
449 |
|
c.await(); |
463 |
|
* hasWaiters throws NPE if null |
464 |
|
*/ |
465 |
|
public void testHasWaitersNPE() { |
466 |
< |
final ReentrantLock lock = new ReentrantLock(); |
466 |
> |
final ReentrantLock lock = new ReentrantLock(); |
467 |
|
try { |
468 |
|
lock.hasWaiters(null); |
469 |
|
shouldThrow(); |
474 |
|
* getWaitQueueLength throws NPE if null |
475 |
|
*/ |
476 |
|
public void testGetWaitQueueLengthNPE() { |
477 |
< |
final ReentrantLock lock = new ReentrantLock(); |
477 |
> |
final ReentrantLock lock = new ReentrantLock(); |
478 |
|
try { |
479 |
|
lock.getWaitQueueLength(null); |
480 |
|
shouldThrow(); |
486 |
|
* getWaitingThreads throws NPE if null |
487 |
|
*/ |
488 |
|
public void testGetWaitingThreadsNPE() { |
489 |
< |
final PublicReentrantLock lock = new PublicReentrantLock(); |
489 |
> |
final PublicReentrantLock lock = new PublicReentrantLock(); |
490 |
|
try { |
491 |
|
lock.getWaitingThreads(null); |
492 |
|
shouldThrow(); |
498 |
|
* hasWaiters throws IAE if not owned |
499 |
|
*/ |
500 |
|
public void testHasWaitersIAE() { |
501 |
< |
final ReentrantLock lock = new ReentrantLock(); |
501 |
> |
final ReentrantLock lock = new ReentrantLock(); |
502 |
|
final Condition c = lock.newCondition(); |
503 |
< |
final ReentrantLock lock2 = new ReentrantLock(); |
503 |
> |
final ReentrantLock lock2 = new ReentrantLock(); |
504 |
|
try { |
505 |
|
lock2.hasWaiters(c); |
506 |
|
shouldThrow(); |
511 |
|
* hasWaiters throws IMSE if not locked |
512 |
|
*/ |
513 |
|
public void testHasWaitersIMSE() { |
514 |
< |
final ReentrantLock lock = new ReentrantLock(); |
514 |
> |
final ReentrantLock lock = new ReentrantLock(); |
515 |
|
final Condition c = lock.newCondition(); |
516 |
|
try { |
517 |
|
lock.hasWaiters(c); |
524 |
|
* getWaitQueueLength throws IAE if not owned |
525 |
|
*/ |
526 |
|
public void testGetWaitQueueLengthIAE() { |
527 |
< |
final ReentrantLock lock = new ReentrantLock(); |
527 |
> |
final ReentrantLock lock = new ReentrantLock(); |
528 |
|
final Condition c = lock.newCondition(); |
529 |
< |
final ReentrantLock lock2 = new ReentrantLock(); |
529 |
> |
final ReentrantLock lock2 = new ReentrantLock(); |
530 |
|
try { |
531 |
|
lock2.getWaitQueueLength(c); |
532 |
|
shouldThrow(); |
537 |
|
* getWaitQueueLength throws IMSE if not locked |
538 |
|
*/ |
539 |
|
public void testGetWaitQueueLengthIMSE() { |
540 |
< |
final ReentrantLock lock = new ReentrantLock(); |
540 |
> |
final ReentrantLock lock = new ReentrantLock(); |
541 |
|
final Condition c = lock.newCondition(); |
542 |
|
try { |
543 |
|
lock.getWaitQueueLength(c); |
550 |
|
* getWaitingThreads throws IAE if not owned |
551 |
|
*/ |
552 |
|
public void testGetWaitingThreadsIAE() { |
553 |
< |
final PublicReentrantLock lock = new PublicReentrantLock(); |
553 |
> |
final PublicReentrantLock lock = new PublicReentrantLock(); |
554 |
|
final Condition c = lock.newCondition(); |
555 |
< |
final PublicReentrantLock lock2 = new PublicReentrantLock(); |
555 |
> |
final PublicReentrantLock lock2 = new PublicReentrantLock(); |
556 |
|
try { |
557 |
|
lock2.getWaitingThreads(c); |
558 |
|
shouldThrow(); |
563 |
|
* getWaitingThreads throws IMSE if not locked |
564 |
|
*/ |
565 |
|
public void testGetWaitingThreadsIMSE() { |
566 |
< |
final PublicReentrantLock lock = new PublicReentrantLock(); |
566 |
> |
final PublicReentrantLock lock = new PublicReentrantLock(); |
567 |
|
final Condition c = lock.newCondition(); |
568 |
|
try { |
569 |
|
lock.getWaitingThreads(c); |
576 |
|
* hasWaiters returns true when a thread is waiting, else false |
577 |
|
*/ |
578 |
|
public void testHasWaiters() throws InterruptedException { |
579 |
< |
final ReentrantLock lock = new ReentrantLock(); |
579 |
> |
final ReentrantLock lock = new ReentrantLock(); |
580 |
|
final Condition c = lock.newCondition(); |
581 |
< |
Thread t = new Thread(new CheckedRunnable() { |
581 |
> |
Thread t = new Thread(new CheckedRunnable() { |
582 |
|
public void realRun() throws InterruptedException { |
583 |
|
lock.lock(); |
584 |
|
threadAssertFalse(lock.hasWaiters(c)); |
607 |
|
* getWaitQueueLength returns number of waiting threads |
608 |
|
*/ |
609 |
|
public void testGetWaitQueueLength() throws InterruptedException { |
610 |
< |
final ReentrantLock lock = new ReentrantLock(); |
610 |
> |
final ReentrantLock lock = new ReentrantLock(); |
611 |
|
final Condition c = lock.newCondition(); |
612 |
< |
Thread t1 = new Thread(new CheckedRunnable() { |
612 |
> |
Thread t1 = new Thread(new CheckedRunnable() { |
613 |
|
public void realRun() throws InterruptedException { |
614 |
|
lock.lock(); |
615 |
|
threadAssertFalse(lock.hasWaiters(c)); |
618 |
|
lock.unlock(); |
619 |
|
}}); |
620 |
|
|
621 |
< |
Thread t2 = new Thread(new CheckedRunnable() { |
621 |
> |
Thread t2 = new Thread(new CheckedRunnable() { |
622 |
|
public void realRun() throws InterruptedException { |
623 |
|
lock.lock(); |
624 |
|
threadAssertTrue(lock.hasWaiters(c)); |
651 |
|
* getWaitingThreads returns only and all waiting threads |
652 |
|
*/ |
653 |
|
public void testGetWaitingThreads() throws InterruptedException { |
654 |
< |
final PublicReentrantLock lock = new PublicReentrantLock(); |
654 |
> |
final PublicReentrantLock lock = new PublicReentrantLock(); |
655 |
|
final Condition c = lock.newCondition(); |
656 |
< |
Thread t1 = new Thread(new CheckedRunnable() { |
656 |
> |
Thread t1 = new Thread(new CheckedRunnable() { |
657 |
|
public void realRun() throws InterruptedException { |
658 |
|
lock.lock(); |
659 |
|
threadAssertTrue(lock.getWaitingThreads(c).isEmpty()); |
661 |
|
lock.unlock(); |
662 |
|
}}); |
663 |
|
|
664 |
< |
Thread t2 = new Thread(new CheckedRunnable() { |
664 |
> |
Thread t2 = new Thread(new CheckedRunnable() { |
665 |
|
public void realRun() throws InterruptedException { |
666 |
|
lock.lock(); |
667 |
|
threadAssertFalse(lock.getWaitingThreads(c).isEmpty()); |
752 |
|
* await is interruptible |
753 |
|
*/ |
754 |
|
public void testAwait_Interrupt() throws InterruptedException { |
755 |
< |
final ReentrantLock lock = new ReentrantLock(); |
755 |
> |
final ReentrantLock lock = new ReentrantLock(); |
756 |
|
final Condition c = lock.newCondition(); |
757 |
< |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
758 |
< |
public void realRun() throws InterruptedException { |
757 |
> |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
758 |
> |
public void realRun() throws InterruptedException { |
759 |
|
lock.lock(); |
760 |
|
c.await(); |
761 |
|
}}); |
771 |
|
* awaitNanos is interruptible |
772 |
|
*/ |
773 |
|
public void testAwaitNanos_Interrupt() throws InterruptedException { |
774 |
< |
final ReentrantLock lock = new ReentrantLock(); |
774 |
> |
final ReentrantLock lock = new ReentrantLock(); |
775 |
|
final Condition c = lock.newCondition(); |
776 |
< |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
777 |
< |
public void realRun() throws InterruptedException { |
776 |
> |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
777 |
> |
public void realRun() throws InterruptedException { |
778 |
|
lock.lock(); |
779 |
< |
c.awaitNanos(1000 * 1000 * 1000); // 1 sec |
779 |
> |
c.awaitNanos(LONG_DELAY_MS * 1000L * 1000L); |
780 |
|
}}); |
781 |
|
|
782 |
|
t.start(); |
790 |
|
* awaitUntil is interruptible |
791 |
|
*/ |
792 |
|
public void testAwaitUntil_Interrupt() throws InterruptedException { |
793 |
< |
final ReentrantLock lock = new ReentrantLock(); |
793 |
> |
final ReentrantLock lock = new ReentrantLock(); |
794 |
|
final Condition c = lock.newCondition(); |
795 |
< |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
796 |
< |
public void realRun() throws InterruptedException { |
795 |
> |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
796 |
> |
public void realRun() throws InterruptedException { |
797 |
|
lock.lock(); |
798 |
|
java.util.Date d = new java.util.Date(); |
799 |
|
c.awaitUntil(new java.util.Date(d.getTime() + 10000)); |
810 |
|
* signalAll wakes up all threads |
811 |
|
*/ |
812 |
|
public void testSignalAll() throws InterruptedException { |
813 |
< |
final ReentrantLock lock = new ReentrantLock(); |
813 |
> |
final ReentrantLock lock = new ReentrantLock(); |
814 |
|
final Condition c = lock.newCondition(); |
815 |
< |
Thread t1 = new Thread(new CheckedRunnable() { |
815 |
> |
Thread t1 = new Thread(new CheckedRunnable() { |
816 |
|
public void realRun() throws InterruptedException { |
817 |
|
lock.lock(); |
818 |
|
c.await(); |
819 |
|
lock.unlock(); |
820 |
|
}}); |
821 |
|
|
822 |
< |
Thread t2 = new Thread(new CheckedRunnable() { |
822 |
> |
Thread t2 = new Thread(new CheckedRunnable() { |
823 |
|
public void realRun() throws InterruptedException { |
824 |
|
lock.lock(); |
825 |
|
c.await(); |
842 |
|
* await after multiple reentrant locking preserves lock count |
843 |
|
*/ |
844 |
|
public void testAwaitLockCount() throws InterruptedException { |
845 |
< |
final ReentrantLock lock = new ReentrantLock(); |
845 |
> |
final ReentrantLock lock = new ReentrantLock(); |
846 |
|
final Condition c = lock.newCondition(); |
847 |
< |
Thread t1 = new Thread(new CheckedRunnable() { |
847 |
> |
Thread t1 = new Thread(new CheckedRunnable() { |
848 |
|
public void realRun() throws InterruptedException { |
849 |
|
lock.lock(); |
850 |
|
threadAssertEquals(1, lock.getHoldCount()); |
853 |
|
lock.unlock(); |
854 |
|
}}); |
855 |
|
|
856 |
< |
Thread t2 = new Thread(new CheckedRunnable() { |
856 |
> |
Thread t2 = new Thread(new CheckedRunnable() { |
857 |
|
public void realRun() throws InterruptedException { |
858 |
|
lock.lock(); |
859 |
|
lock.lock(); |