ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ReentrantLockTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ReentrantLockTest.java (file contents):
Revision 1.38 by jsr166, Sat Oct 9 19:30:35 2010 UTC vs.
Revision 1.44 by jsr166, Sat May 7 03:40:45 2011 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   * Other contributors include Andrew Wright, Jeffrey Hayes,
6   * Pat Fisher, Mike Judd.
7   */
# Line 59 | Line 59 | public class ReentrantLockTest extends J
59      }
60  
61      /**
62 +     * Checks that condition c has no waiters.
63 +     */
64 +    void assertHasNoWaiters(PublicReentrantLock lock, Condition c) {
65 +        assertHasWaiters(lock, c, new Thread[] {});
66 +    }
67 +
68 +    /**
69 +     * Checks that condition c has exactly the given waiter threads.
70 +     */
71 +    void assertHasWaiters(PublicReentrantLock lock, Condition c,
72 +                          Thread... threads) {
73 +        lock.lock();
74 +        assertEquals(threads.length > 0, lock.hasWaiters(c));
75 +        assertEquals(threads.length, lock.getWaitQueueLength(c));
76 +        assertEquals(threads.length == 0, lock.getWaitingThreads(c).isEmpty());
77 +        assertEquals(threads.length, lock.getWaitingThreads(c).size());
78 +        assertEquals(new HashSet<Thread>(lock.getWaitingThreads(c)),
79 +                     new HashSet<Thread>(Arrays.asList(threads)));
80 +        lock.unlock();
81 +    }
82 +
83 +    /**
84       * Constructor sets given fairness
85       */
86      public void testConstructor() {
# Line 120 | Line 142 | public class ReentrantLockTest extends J
142          assertFalse(lock.hasQueuedThreads());
143          lock.lock();
144          t1.start();
145 <        Thread.sleep(SHORT_DELAY_MS);
145 >        delay(SHORT_DELAY_MS);
146          assertTrue(lock.hasQueuedThreads());
147          t2.start();
148 <        Thread.sleep(SHORT_DELAY_MS);
148 >        delay(SHORT_DELAY_MS);
149          assertTrue(lock.hasQueuedThreads());
150          t1.interrupt();
151 <        Thread.sleep(SHORT_DELAY_MS);
151 >        delay(SHORT_DELAY_MS);
152          assertTrue(lock.hasQueuedThreads());
153          lock.unlock();
154 <        Thread.sleep(SHORT_DELAY_MS);
154 >        delay(SHORT_DELAY_MS);
155          assertFalse(lock.hasQueuedThreads());
156 <        t1.join();
157 <        t2.join();
156 >        awaitTermination(t1);
157 >        awaitTermination(t2);
158      }
159  
160      /**
# Line 145 | Line 167 | public class ReentrantLockTest extends J
167          assertEquals(0, lock.getQueueLength());
168          lock.lock();
169          t1.start();
170 <        Thread.sleep(SHORT_DELAY_MS);
170 >        delay(SHORT_DELAY_MS);
171          assertEquals(1, lock.getQueueLength());
172          t2.start();
173 <        Thread.sleep(SHORT_DELAY_MS);
173 >        delay(SHORT_DELAY_MS);
174          assertEquals(2, lock.getQueueLength());
175          t1.interrupt();
176 <        Thread.sleep(SHORT_DELAY_MS);
176 >        delay(SHORT_DELAY_MS);
177          assertEquals(1, lock.getQueueLength());
178          lock.unlock();
179 <        Thread.sleep(SHORT_DELAY_MS);
179 >        delay(SHORT_DELAY_MS);
180          assertEquals(0, lock.getQueueLength());
181 <        t1.join();
182 <        t2.join();
181 >        awaitTermination(t1);
182 >        awaitTermination(t2);
183      }
184  
185      /**
# Line 170 | Line 192 | public class ReentrantLockTest extends J
192          assertEquals(0, lock.getQueueLength());
193          lock.lock();
194          t1.start();
195 <        Thread.sleep(SHORT_DELAY_MS);
195 >        delay(SHORT_DELAY_MS);
196          assertEquals(1, lock.getQueueLength());
197          t2.start();
198 <        Thread.sleep(SHORT_DELAY_MS);
198 >        delay(SHORT_DELAY_MS);
199          assertEquals(2, lock.getQueueLength());
200          t1.interrupt();
201 <        Thread.sleep(SHORT_DELAY_MS);
201 >        delay(SHORT_DELAY_MS);
202          assertEquals(1, lock.getQueueLength());
203          lock.unlock();
204 <        Thread.sleep(SHORT_DELAY_MS);
204 >        delay(SHORT_DELAY_MS);
205          assertEquals(0, lock.getQueueLength());
206 <        t1.join();
207 <        t2.join();
206 >        awaitTermination(t1);
207 >        awaitTermination(t2);
208      }
209  
210      /**
# Line 207 | Line 229 | public class ReentrantLockTest extends J
229          assertFalse(sync.hasQueuedThread(t2));
230          sync.lock();
231          t1.start();
232 <        Thread.sleep(SHORT_DELAY_MS);
232 >        delay(SHORT_DELAY_MS);
233          assertTrue(sync.hasQueuedThread(t1));
234          t2.start();
235 <        Thread.sleep(SHORT_DELAY_MS);
235 >        delay(SHORT_DELAY_MS);
236          assertTrue(sync.hasQueuedThread(t1));
237          assertTrue(sync.hasQueuedThread(t2));
238          t1.interrupt();
239 <        Thread.sleep(SHORT_DELAY_MS);
239 >        delay(SHORT_DELAY_MS);
240          assertFalse(sync.hasQueuedThread(t1));
241          assertTrue(sync.hasQueuedThread(t2));
242          sync.unlock();
243 <        Thread.sleep(SHORT_DELAY_MS);
243 >        delay(SHORT_DELAY_MS);
244          assertFalse(sync.hasQueuedThread(t1));
245 <        Thread.sleep(SHORT_DELAY_MS);
245 >        delay(SHORT_DELAY_MS);
246          assertFalse(sync.hasQueuedThread(t2));
247 <        t1.join();
248 <        t2.join();
247 >        awaitTermination(t1);
248 >        awaitTermination(t2);
249      }
250  
251  
# Line 238 | Line 260 | public class ReentrantLockTest extends J
260          lock.lock();
261          assertTrue(lock.getQueuedThreads().isEmpty());
262          t1.start();
263 <        Thread.sleep(SHORT_DELAY_MS);
263 >        delay(SHORT_DELAY_MS);
264          assertTrue(lock.getQueuedThreads().contains(t1));
265          t2.start();
266 <        Thread.sleep(SHORT_DELAY_MS);
266 >        delay(SHORT_DELAY_MS);
267          assertTrue(lock.getQueuedThreads().contains(t1));
268          assertTrue(lock.getQueuedThreads().contains(t2));
269          t1.interrupt();
270 <        Thread.sleep(SHORT_DELAY_MS);
270 >        delay(SHORT_DELAY_MS);
271          assertFalse(lock.getQueuedThreads().contains(t1));
272          assertTrue(lock.getQueuedThreads().contains(t2));
273          lock.unlock();
274 <        Thread.sleep(SHORT_DELAY_MS);
274 >        delay(SHORT_DELAY_MS);
275          assertTrue(lock.getQueuedThreads().isEmpty());
276 <        t1.join();
277 <        t2.join();
276 >        awaitTermination(t1);
277 >        awaitTermination(t2);
278      }
279  
280  
# Line 262 | Line 284 | public class ReentrantLockTest extends J
284      public void testInterruptedException2() throws InterruptedException {
285          final ReentrantLock lock = new ReentrantLock();
286          lock.lock();
287 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
287 >        Thread t = newStartedThread(new CheckedInterruptedRunnable() {
288              public void realRun() throws InterruptedException {
289                  lock.tryLock(MEDIUM_DELAY_MS,MILLISECONDS);
290              }});
291  
292 <        t.start();
271 <        Thread.sleep(SHORT_DELAY_MS);
292 >        delay(SHORT_DELAY_MS);
293          t.interrupt();
294 <        t.join();
294 >        awaitTermination(t);
295      }
296  
297  
# Line 280 | Line 301 | public class ReentrantLockTest extends J
301      public void testTryLockWhenLocked() throws InterruptedException {
302          final ReentrantLock lock = new ReentrantLock();
303          lock.lock();
304 <        Thread t = new Thread(new CheckedRunnable() {
304 >        Thread t = newStartedThread(new CheckedRunnable() {
305              public void realRun() {
306                  assertFalse(lock.tryLock());
307              }});
308  
309 <        t.start();
289 <        t.join();
309 >        awaitTermination(t);
310          lock.unlock();
311      }
312  
# Line 296 | Line 316 | public class ReentrantLockTest extends J
316      public void testTryLock_Timeout() throws InterruptedException {
317          final ReentrantLock lock = new ReentrantLock();
318          lock.lock();
319 <        Thread t = new Thread(new CheckedRunnable() {
319 >        Thread t = newStartedThread(new CheckedRunnable() {
320              public void realRun() throws InterruptedException {
321                  assertFalse(lock.tryLock(1, MILLISECONDS));
322              }});
323  
324 <        t.start();
305 <        t.join();
324 >        awaitTermination(t);
325          lock.unlock();
326      }
327  
# Line 331 | Line 350 | public class ReentrantLockTest extends J
350          assertTrue(lock.isLocked());
351          lock.unlock();
352          assertFalse(lock.isLocked());
353 <        Thread t = new Thread(new CheckedRunnable() {
353 >        Thread t = newStartedThread(new CheckedRunnable() {
354              public void realRun() throws InterruptedException {
355                  lock.lock();
356 <                Thread.sleep(SMALL_DELAY_MS);
356 >                delay(SMALL_DELAY_MS);
357                  lock.unlock();
358              }});
359  
360 <        t.start();
342 <        Thread.sleep(SHORT_DELAY_MS);
360 >        delay(SHORT_DELAY_MS);
361          assertTrue(lock.isLocked());
362 <        t.join();
362 >        awaitTermination(t);
363          assertFalse(lock.isLocked());
364      }
365  
# Line 352 | Line 370 | public class ReentrantLockTest extends J
370      public void testLockInterruptibly1() throws InterruptedException {
371          final ReentrantLock lock = new ReentrantLock();
372          lock.lock();
373 <        Thread t = new Thread(new InterruptedLockRunnable(lock));
374 <        t.start();
357 <        Thread.sleep(SHORT_DELAY_MS);
373 >        Thread t = newStartedThread(new InterruptedLockRunnable(lock));
374 >        delay(SHORT_DELAY_MS);
375          t.interrupt();
376 <        Thread.sleep(SHORT_DELAY_MS);
376 >        delay(SHORT_DELAY_MS);
377          lock.unlock();
378 <        t.join();
378 >        awaitTermination(t);
379      }
380  
381      /**
# Line 367 | Line 384 | public class ReentrantLockTest extends J
384      public void testLockInterruptibly2() throws InterruptedException {
385          final ReentrantLock lock = new ReentrantLock();
386          lock.lockInterruptibly();
387 <        Thread t = new Thread(new InterruptedLockRunnable(lock));
388 <        t.start();
372 <        Thread.sleep(SHORT_DELAY_MS);
387 >        Thread t = newStartedThread(new InterruptedLockRunnable(lock));
388 >        delay(SHORT_DELAY_MS);
389          t.interrupt();
390          assertTrue(lock.isLocked());
391          assertTrue(lock.isHeldByCurrentThread());
392 <        t.join();
392 >        awaitTermination(t);
393      }
394  
395      /**
# Line 441 | Line 457 | public class ReentrantLockTest extends J
457      public void testAwait() throws InterruptedException {
458          final ReentrantLock lock = new ReentrantLock();
459          final Condition c = lock.newCondition();
460 <        Thread t = new Thread(new CheckedRunnable() {
460 >        Thread t = newStartedThread(new CheckedRunnable() {
461              public void realRun() throws InterruptedException {
462                  lock.lock();
463                  c.await();
464                  lock.unlock();
465              }});
466  
467 <        t.start();
452 <        Thread.sleep(SHORT_DELAY_MS);
467 >        delay(SHORT_DELAY_MS);
468          lock.lock();
469          c.signal();
470          lock.unlock();
471 <        t.join(SHORT_DELAY_MS);
457 <        assertFalse(t.isAlive());
471 >        awaitTermination(t);
472      }
473  
474      /**
# Line 576 | Line 590 | public class ReentrantLockTest extends J
590      public void testHasWaiters() throws InterruptedException {
591          final ReentrantLock lock = new ReentrantLock();
592          final Condition c = lock.newCondition();
593 <        Thread t = new Thread(new CheckedRunnable() {
593 >        Thread t = newStartedThread(new CheckedRunnable() {
594              public void realRun() throws InterruptedException {
595                  lock.lock();
596                  assertFalse(lock.hasWaiters(c));
# Line 585 | Line 599 | public class ReentrantLockTest extends J
599                  lock.unlock();
600              }});
601  
602 <        t.start();
589 <        Thread.sleep(SHORT_DELAY_MS);
602 >        delay(SHORT_DELAY_MS);
603          lock.lock();
604          assertTrue(lock.hasWaiters(c));
605          assertEquals(1, lock.getWaitQueueLength(c));
606          c.signal();
607          lock.unlock();
608 <        Thread.sleep(SHORT_DELAY_MS);
608 >        delay(SHORT_DELAY_MS);
609          lock.lock();
610          assertFalse(lock.hasWaiters(c));
611          assertEquals(0, lock.getWaitQueueLength(c));
612          lock.unlock();
613 <        t.join(SHORT_DELAY_MS);
601 <        assertFalse(t.isAlive());
613 >        awaitTermination(t);
614      }
615  
616      /**
# Line 607 | Line 619 | public class ReentrantLockTest extends J
619      public void testGetWaitQueueLength() throws InterruptedException {
620          final ReentrantLock lock = new ReentrantLock();
621          final Condition c = lock.newCondition();
622 <        Thread t1 = new Thread(new CheckedRunnable() {
622 >        Thread t1 = newStartedThread(new CheckedRunnable() {
623              public void realRun() throws InterruptedException {
624                  lock.lock();
625                  assertFalse(lock.hasWaiters(c));
# Line 616 | Line 628 | public class ReentrantLockTest extends J
628                  lock.unlock();
629              }});
630  
631 <        Thread t2 = new Thread(new CheckedRunnable() {
631 >        delay(SHORT_DELAY_MS);
632 >
633 >        Thread t2 = newStartedThread(new CheckedRunnable() {
634              public void realRun() throws InterruptedException {
635                  lock.lock();
636                  assertTrue(lock.hasWaiters(c));
# Line 625 | Line 639 | public class ReentrantLockTest extends J
639                  lock.unlock();
640              }});
641  
642 <        t1.start();
629 <        Thread.sleep(SHORT_DELAY_MS);
630 <        t2.start();
631 <        Thread.sleep(SHORT_DELAY_MS);
642 >        delay(SHORT_DELAY_MS);
643          lock.lock();
644          assertTrue(lock.hasWaiters(c));
645          assertEquals(2, lock.getWaitQueueLength(c));
646          c.signalAll();
647          lock.unlock();
648 <        Thread.sleep(SHORT_DELAY_MS);
648 >        delay(SHORT_DELAY_MS);
649          lock.lock();
650          assertFalse(lock.hasWaiters(c));
651          assertEquals(0, lock.getWaitQueueLength(c));
652          lock.unlock();
653 <        t1.join(SHORT_DELAY_MS);
654 <        t2.join(SHORT_DELAY_MS);
644 <        assertFalse(t1.isAlive());
645 <        assertFalse(t2.isAlive());
653 >        awaitTermination(t1);
654 >        awaitTermination(t2);
655      }
656  
657      /**
# Line 671 | Line 680 | public class ReentrantLockTest extends J
680          assertTrue(lock.getWaitingThreads(c).isEmpty());
681          lock.unlock();
682          t1.start();
683 <        Thread.sleep(SHORT_DELAY_MS);
683 >        delay(SHORT_DELAY_MS);
684          t2.start();
685 <        Thread.sleep(SHORT_DELAY_MS);
685 >        delay(SHORT_DELAY_MS);
686          lock.lock();
687          assertTrue(lock.hasWaiters(c));
688          assertTrue(lock.getWaitingThreads(c).contains(t1));
689          assertTrue(lock.getWaitingThreads(c).contains(t2));
690          c.signalAll();
691          lock.unlock();
692 <        Thread.sleep(SHORT_DELAY_MS);
692 >        delay(SHORT_DELAY_MS);
693          lock.lock();
694          assertFalse(lock.hasWaiters(c));
695          assertTrue(lock.getWaitingThreads(c).isEmpty());
696          lock.unlock();
697 <        t1.join(SHORT_DELAY_MS);
698 <        t2.join(SHORT_DELAY_MS);
690 <        assertFalse(t1.isAlive());
691 <        assertFalse(t2.isAlive());
697 >        awaitTermination(t1);
698 >        awaitTermination(t2);
699      }
700  
701      /** A helper class for uninterruptible wait tests */
# Line 729 | Line 736 | public class ReentrantLockTest extends J
736          thread.start();
737  
738          while (!thread.lockStarted) {
739 <            Thread.sleep(100);
739 >            delay(100);
740          }
741  
742          lock.lock();
# Line 750 | Line 757 | public class ReentrantLockTest extends J
757       * await is interruptible
758       */
759      public void testAwait_Interrupt() throws InterruptedException {
760 <        final ReentrantLock lock = new ReentrantLock();
760 >        final PublicReentrantLock lock = new PublicReentrantLock();
761          final Condition c = lock.newCondition();
762 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
762 >        final CountDownLatch locked = new CountDownLatch(1);
763 >        Thread t = newStartedThread(new CheckedInterruptedRunnable() {
764              public void realRun() throws InterruptedException {
765                  lock.lock();
766 <                c.await();
766 >                assertTrue(lock.isLocked());
767 >                assertTrue(lock.isHeldByCurrentThread());
768 >                assertHasNoWaiters(lock, c);
769 >                locked.countDown();
770 >                try {
771 >                    c.await();
772 >                } finally {
773 >                    assertTrue(lock.isLocked());
774 >                    assertTrue(lock.isHeldByCurrentThread());
775 >                    assertHasNoWaiters(lock, c);
776 >                    lock.unlock();
777 >                    assertFalse(Thread.interrupted());
778 >                }
779              }});
780  
781 <        t.start();
782 <        Thread.sleep(SHORT_DELAY_MS);
781 >        locked.await();
782 >        assertHasWaiters(lock, c, t);
783          t.interrupt();
784 <        t.join(SHORT_DELAY_MS);
785 <        assertFalse(t.isAlive());
784 >        awaitTermination(t);
785 >        assertFalse(lock.isLocked());
786      }
787  
788      /**
789       * awaitNanos is interruptible
790       */
791      public void testAwaitNanos_Interrupt() throws InterruptedException {
792 <        final ReentrantLock lock = new ReentrantLock();
792 >        final PublicReentrantLock lock = new PublicReentrantLock();
793          final Condition c = lock.newCondition();
794 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
794 >        final CountDownLatch locked = new CountDownLatch(1);
795 >        Thread t = newStartedThread(new CheckedInterruptedRunnable() {
796              public void realRun() throws InterruptedException {
797                  lock.lock();
798 <                c.awaitNanos(MILLISECONDS.toNanos(LONG_DELAY_MS));
798 >                assertTrue(lock.isLocked());
799 >                assertTrue(lock.isHeldByCurrentThread());
800 >                assertHasNoWaiters(lock, c);
801 >                locked.countDown();
802 >                try {
803 >                    c.awaitNanos(MILLISECONDS.toNanos(LONG_DELAY_MS));
804 >                } finally {
805 >                    assertTrue(lock.isLocked());
806 >                    assertTrue(lock.isHeldByCurrentThread());
807 >                    assertHasNoWaiters(lock, c);
808 >                    lock.unlock();
809 >                    assertFalse(Thread.interrupted());
810 >                }
811              }});
812  
813 <        t.start();
814 <        Thread.sleep(SHORT_DELAY_MS);
813 >        locked.await();
814 >        assertHasWaiters(lock, c, t);
815          t.interrupt();
816 <        t.join(SHORT_DELAY_MS);
817 <        assertFalse(t.isAlive());
816 >        awaitTermination(t);
817 >        assertFalse(lock.isLocked());
818      }
819  
820      /**
821       * awaitUntil is interruptible
822       */
823      public void testAwaitUntil_Interrupt() throws InterruptedException {
824 <        final ReentrantLock lock = new ReentrantLock();
824 >        final PublicReentrantLock lock = new PublicReentrantLock();
825          final Condition c = lock.newCondition();
826 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
826 >        final CountDownLatch locked = new CountDownLatch(1);
827 >        Thread t = newStartedThread(new CheckedInterruptedRunnable() {
828              public void realRun() throws InterruptedException {
829                  lock.lock();
830 +                assertTrue(lock.isLocked());
831 +                assertTrue(lock.isHeldByCurrentThread());
832 +                assertHasNoWaiters(lock, c);
833 +                locked.countDown();
834                  java.util.Date d = new java.util.Date();
835 <                c.awaitUntil(new java.util.Date(d.getTime() + 10000));
835 >                try {
836 >                    c.awaitUntil(new java.util.Date(d.getTime() + 10000));
837 >                } finally {
838 >                    assertTrue(lock.isLocked());
839 >                    assertTrue(lock.isHeldByCurrentThread());
840 >                    assertHasNoWaiters(lock, c);
841 >                    lock.unlock();
842 >                    assertFalse(Thread.interrupted());
843 >                }
844              }});
845  
846 <        t.start();
847 <        Thread.sleep(SHORT_DELAY_MS);
846 >        locked.await();
847 >        assertHasWaiters(lock, c, t);
848          t.interrupt();
849 <        t.join(SHORT_DELAY_MS);
850 <        assertFalse(t.isAlive());
849 >        awaitTermination(t);
850 >        assertFalse(lock.isLocked());
851      }
852  
853      /**
# Line 810 | Line 856 | public class ReentrantLockTest extends J
856      public void testSignalAll() throws InterruptedException {
857          final ReentrantLock lock = new ReentrantLock();
858          final Condition c = lock.newCondition();
859 <        Thread t1 = new Thread(new CheckedRunnable() {
859 >        Thread t1 = newStartedThread(new CheckedRunnable() {
860              public void realRun() throws InterruptedException {
861                  lock.lock();
862                  c.await();
863                  lock.unlock();
864              }});
865  
866 <        Thread t2 = new Thread(new CheckedRunnable() {
866 >        Thread t2 = newStartedThread(new CheckedRunnable() {
867              public void realRun() throws InterruptedException {
868                  lock.lock();
869                  c.await();
870                  lock.unlock();
871              }});
872  
873 <        t1.start();
828 <        t2.start();
829 <        Thread.sleep(SHORT_DELAY_MS);
873 >        delay(SHORT_DELAY_MS);
874          lock.lock();
875          c.signalAll();
876          lock.unlock();
877 <        t1.join(SHORT_DELAY_MS);
878 <        t2.join(SHORT_DELAY_MS);
835 <        assertFalse(t1.isAlive());
836 <        assertFalse(t2.isAlive());
877 >        awaitTermination(t1);
878 >        awaitTermination(t2);
879      }
880  
881      /**
# Line 842 | Line 884 | public class ReentrantLockTest extends J
884      public void testAwaitLockCount() throws InterruptedException {
885          final ReentrantLock lock = new ReentrantLock();
886          final Condition c = lock.newCondition();
887 <        Thread t1 = new Thread(new CheckedRunnable() {
887 >        Thread t1 = newStartedThread(new CheckedRunnable() {
888              public void realRun() throws InterruptedException {
889                  lock.lock();
890                  assertEquals(1, lock.getHoldCount());
# Line 851 | Line 893 | public class ReentrantLockTest extends J
893                  lock.unlock();
894              }});
895  
896 <        Thread t2 = new Thread(new CheckedRunnable() {
896 >        Thread t2 = newStartedThread(new CheckedRunnable() {
897              public void realRun() throws InterruptedException {
898                  lock.lock();
899                  lock.lock();
# Line 862 | Line 904 | public class ReentrantLockTest extends J
904                  lock.unlock();
905              }});
906  
907 <        t1.start();
866 <        t2.start();
867 <        Thread.sleep(SHORT_DELAY_MS);
907 >        delay(SHORT_DELAY_MS);
908          lock.lock();
909          c.signalAll();
910          lock.unlock();
911 <        t1.join(SHORT_DELAY_MS);
912 <        t2.join(SHORT_DELAY_MS);
873 <        assertFalse(t1.isAlive());
874 <        assertFalse(t2.isAlive());
911 >        awaitTermination(t1);
912 >        awaitTermination(t2);
913      }
914  
915      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines