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

Comparing jsr166/src/test/tck/ReentrantReadWriteLockTest.java (file contents):
Revision 1.32 by jsr166, Tue Nov 17 14:18:28 2009 UTC vs.
Revision 1.37 by jsr166, Sat Nov 21 10:25:05 2009 UTC

# Line 9 | Line 9
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.io.*;
14   import java.util.*;
15  
16   public class ReentrantReadWriteLockTest 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(ReentrantReadWriteLockTest.class);
21 >        return new TestSuite(ReentrantReadWriteLockTest.class);
22      }
23  
24      /**
# Line 61 | Line 62 | public class ReentrantReadWriteLockTest
62       * Constructor sets given fairness, and is in unlocked state
63       */
64      public void testConstructor() {
65 <        ReentrantReadWriteLock rl = new ReentrantReadWriteLock();
65 >        ReentrantReadWriteLock rl = new ReentrantReadWriteLock();
66          assertFalse(rl.isFair());
67          assertFalse(rl.isWriteLocked());
68          assertEquals(0, rl.getReadLockCount());
69 <        ReentrantReadWriteLock r2 = new ReentrantReadWriteLock(true);
69 >        ReentrantReadWriteLock r2 = new ReentrantReadWriteLock(true);
70          assertTrue(r2.isFair());
71          assertFalse(r2.isWriteLocked());
72          assertEquals(0, r2.getReadLockCount());
73 <        ReentrantReadWriteLock r3 = new ReentrantReadWriteLock(false);
73 >        ReentrantReadWriteLock r3 = new ReentrantReadWriteLock(false);
74          assertFalse(r3.isFair());
75          assertFalse(r3.isWriteLocked());
76          assertEquals(0, r3.getReadLockCount());
# Line 79 | Line 80 | public class ReentrantReadWriteLockTest
80       * write-locking and read-locking an unlocked lock succeed
81       */
82      public void testLock() {
83 <        ReentrantReadWriteLock rl = new ReentrantReadWriteLock();
83 >        ReentrantReadWriteLock rl = new ReentrantReadWriteLock();
84          rl.writeLock().lock();
85          assertTrue(rl.isWriteLocked());
86          assertTrue(rl.isWriteLockedByCurrentThread());
# Line 105 | Line 106 | public class ReentrantReadWriteLockTest
106       * locking an unlocked fair lock succeeds
107       */
108      public void testFairLock() {
109 <        ReentrantReadWriteLock rl = new ReentrantReadWriteLock(true);
109 >        ReentrantReadWriteLock rl = new ReentrantReadWriteLock(true);
110          rl.writeLock().lock();
111          assertTrue(rl.isWriteLocked());
112          assertTrue(rl.isWriteLockedByCurrentThread());
# Line 130 | Line 131 | public class ReentrantReadWriteLockTest
131       * getWriteHoldCount returns number of recursive holds
132       */
133      public void testGetWriteHoldCount() {
134 <        ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
135 <        for (int i = 1; i <= SIZE; i++) {
136 <            lock.writeLock().lock();
137 <            assertEquals(i,lock.getWriteHoldCount());
138 <        }
139 <        for (int i = SIZE; i > 0; i--) {
140 <            lock.writeLock().unlock();
141 <            assertEquals(i-1,lock.getWriteHoldCount());
142 <        }
134 >        ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
135 >        for (int i = 1; i <= SIZE; i++) {
136 >            lock.writeLock().lock();
137 >            assertEquals(i,lock.getWriteHoldCount());
138 >        }
139 >        for (int i = SIZE; i > 0; i--) {
140 >            lock.writeLock().unlock();
141 >            assertEquals(i-1,lock.getWriteHoldCount());
142 >        }
143      }
144  
145      /**
146       * WriteLock.getHoldCount returns number of recursive holds
147       */
148      public void testGetHoldCount() {
149 <        ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
150 <        for (int i = 1; i <= SIZE; i++) {
151 <            lock.writeLock().lock();
152 <            assertEquals(i,lock.writeLock().getHoldCount());
153 <        }
154 <        for (int i = SIZE; i > 0; i--) {
155 <            lock.writeLock().unlock();
156 <            assertEquals(i-1,lock.writeLock().getHoldCount());
157 <        }
149 >        ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
150 >        for (int i = 1; i <= SIZE; i++) {
151 >            lock.writeLock().lock();
152 >            assertEquals(i,lock.writeLock().getHoldCount());
153 >        }
154 >        for (int i = SIZE; i > 0; i--) {
155 >            lock.writeLock().unlock();
156 >            assertEquals(i-1,lock.writeLock().getHoldCount());
157 >        }
158      }
159  
160      /**
161       * getReadHoldCount returns number of recursive holds
162       */
163      public void testGetReadHoldCount() {
164 <        ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
165 <        for (int i = 1; i <= SIZE; i++) {
166 <            lock.readLock().lock();
167 <            assertEquals(i,lock.getReadHoldCount());
168 <        }
169 <        for (int i = SIZE; i > 0; i--) {
170 <            lock.readLock().unlock();
171 <            assertEquals(i-1,lock.getReadHoldCount());
172 <        }
164 >        ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
165 >        for (int i = 1; i <= SIZE; i++) {
166 >            lock.readLock().lock();
167 >            assertEquals(i,lock.getReadHoldCount());
168 >        }
169 >        for (int i = SIZE; i > 0; i--) {
170 >            lock.readLock().unlock();
171 >            assertEquals(i-1,lock.getReadHoldCount());
172 >        }
173      }
174  
175  
# Line 176 | Line 177 | public class ReentrantReadWriteLockTest
177       * write-unlocking an unlocked lock throws IllegalMonitorStateException
178       */
179      public void testUnlock_IllegalMonitorStateException() {
180 <        ReentrantReadWriteLock rl = new ReentrantReadWriteLock();
181 <        try {
182 <            rl.writeLock().unlock();
183 <            shouldThrow();
184 <        } catch (IllegalMonitorStateException success) {}
180 >        ReentrantReadWriteLock rl = new ReentrantReadWriteLock();
181 >        try {
182 >            rl.writeLock().unlock();
183 >            shouldThrow();
184 >        } catch (IllegalMonitorStateException success) {}
185      }
186  
187  
# Line 188 | Line 189 | public class ReentrantReadWriteLockTest
189       * write-lockInterruptibly is interruptible
190       */
191      public void testWriteLockInterruptibly_Interrupted() throws Exception {
192 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
193 <        Thread t = new Thread(new Runnable() {
194 <                public void run() {
195 <                    try {
196 <                        lock.writeLock().lockInterruptibly();
197 <                        lock.writeLock().unlock();
198 <                        lock.writeLock().lockInterruptibly();
199 <                        lock.writeLock().unlock();
199 <                    } catch (InterruptedException success) {}
200 <                }
201 <            });
192 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
193 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
194 >            public void realRun() throws InterruptedException {
195 >                lock.writeLock().lockInterruptibly();
196 >                lock.writeLock().unlock();
197 >                lock.writeLock().lockInterruptibly();
198 >                lock.writeLock().unlock();
199 >            }});
200  
201          lock.writeLock().lock();
202          t.start();
# Line 213 | Line 211 | public class ReentrantReadWriteLockTest
211       * timed write-tryLock is interruptible
212       */
213      public void testWriteTryLock_Interrupted() throws InterruptedException {
214 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
215 <        lock.writeLock().lock();
216 <        Thread t = new Thread(new Runnable() {
217 <                public void run() {
218 <                    try {
219 <                        lock.writeLock().tryLock(1000,TimeUnit.MILLISECONDS);
222 <                    } catch (InterruptedException success) {}
223 <                }
224 <            });
214 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
215 >        lock.writeLock().lock();
216 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
217 >            public void realRun() throws InterruptedException {
218 >                lock.writeLock().tryLock(1000,MILLISECONDS);
219 >            }});
220  
221          t.start();
222          t.interrupt();
# Line 233 | Line 228 | public class ReentrantReadWriteLockTest
228       * read-lockInterruptibly is interruptible
229       */
230      public void testReadLockInterruptibly_Interrupted() throws InterruptedException {
231 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
232 <        lock.writeLock().lock();
233 <        Thread t = new Thread(new Runnable() {
234 <                public void run() {
235 <                    try {
236 <                        lock.readLock().lockInterruptibly();
242 <                    } catch (InterruptedException success) {}
243 <                }
244 <            });
231 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
232 >        lock.writeLock().lock();
233 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
234 >            public void realRun() throws InterruptedException {
235 >                lock.readLock().lockInterruptibly();
236 >            }});
237  
238          t.start();
239          Thread.sleep(SHORT_DELAY_MS);
# Line 255 | Line 247 | public class ReentrantReadWriteLockTest
247       * timed read-tryLock is interruptible
248       */
249      public void testReadTryLock_Interrupted() throws InterruptedException {
250 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
251 <        lock.writeLock().lock();
252 <        Thread t = new Thread(new Runnable() {
253 <                public void run() {
254 <                    try {
255 <                        lock.readLock().tryLock(1000,TimeUnit.MILLISECONDS);
264 <                        threadShouldThrow();
265 <                    } catch (InterruptedException success) {}
266 <                }
267 <            });
250 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
251 >        lock.writeLock().lock();
252 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
253 >            public void realRun() throws InterruptedException {
254 >                lock.readLock().tryLock(1000,MILLISECONDS);
255 >            }});
256  
257          t.start();
258          t.interrupt();
# Line 276 | Line 264 | public class ReentrantReadWriteLockTest
264       * write-tryLock fails if locked
265       */
266      public void testWriteTryLockWhenLocked() throws InterruptedException {
267 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
268 <        lock.writeLock().lock();
269 <        Thread t = new Thread(new Runnable() {
270 <                public void run() {
271 <                    threadAssertFalse(lock.writeLock().tryLock());
272 <                }
285 <            });
267 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
268 >        lock.writeLock().lock();
269 >        Thread t = new Thread(new CheckedRunnable() {
270 >            public void realRun() {
271 >                threadAssertFalse(lock.writeLock().tryLock());
272 >            }});
273  
274          t.start();
275          t.join();
# Line 293 | Line 280 | public class ReentrantReadWriteLockTest
280       * read-tryLock fails if locked
281       */
282      public void testReadTryLockWhenLocked() throws InterruptedException {
283 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
284 <        lock.writeLock().lock();
285 <        Thread t = new Thread(new Runnable() {
286 <                public void run() {
287 <                    threadAssertFalse(lock.readLock().tryLock());
288 <                }
302 <            });
283 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
284 >        lock.writeLock().lock();
285 >        Thread t = new Thread(new CheckedRunnable() {
286 >            public void realRun() {
287 >                threadAssertFalse(lock.readLock().tryLock());
288 >            }});
289  
290          t.start();
291          t.join();
# Line 310 | Line 296 | public class ReentrantReadWriteLockTest
296       * Multiple threads can hold a read lock when not write-locked
297       */
298      public void testMultipleReadLocks() throws InterruptedException {
299 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
300 <        lock.readLock().lock();
301 <        Thread t = new Thread(new Runnable() {
302 <                public void run() {
303 <                    threadAssertTrue(lock.readLock().tryLock());
304 <                    lock.readLock().unlock();
305 <                }
320 <            });
299 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
300 >        lock.readLock().lock();
301 >        Thread t = new Thread(new CheckedRunnable() {
302 >            public void realRun() {
303 >                threadAssertTrue(lock.readLock().tryLock());
304 >                lock.readLock().unlock();
305 >            }});
306  
307          t.start();
308          t.join();
# Line 328 | Line 313 | public class ReentrantReadWriteLockTest
313       * A writelock succeeds after reading threads unlock
314       */
315      public void testWriteAfterMultipleReadLocks() throws InterruptedException {
316 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
317 <        lock.readLock().lock();
318 <        Thread t1 = new Thread(new Runnable() {
319 <                public void run() {
320 <                    lock.readLock().lock();
321 <                    lock.readLock().unlock();
322 <                }
323 <            });
324 <        Thread t2 = new Thread(new Runnable() {
325 <                public void run() {
326 <                    lock.writeLock().lock();
327 <                    lock.writeLock().unlock();
343 <                }
344 <            });
316 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
317 >        lock.readLock().lock();
318 >        Thread t1 = new Thread(new CheckedRunnable() {
319 >            public void realRun() {
320 >                lock.readLock().lock();
321 >                lock.readLock().unlock();
322 >            }});
323 >        Thread t2 = new Thread(new CheckedRunnable() {
324 >            public void realRun() {
325 >                lock.writeLock().lock();
326 >                lock.writeLock().unlock();
327 >            }});
328  
329          t1.start();
330          t2.start();
# Line 357 | Line 340 | public class ReentrantReadWriteLockTest
340       * Readlocks succeed after a writing thread unlocks
341       */
342      public void testReadAfterWriteLock() throws InterruptedException {
343 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
344 <        lock.writeLock().lock();
345 <        Thread t1 = new Thread(new Runnable() {
346 <                public void run() {
347 <                    lock.readLock().lock();
348 <                    lock.readLock().unlock();
349 <                }
350 <            });
351 <        Thread t2 = new Thread(new Runnable() {
352 <                public void run() {
353 <                    lock.readLock().lock();
354 <                    lock.readLock().unlock();
372 <                }
373 <            });
343 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
344 >        lock.writeLock().lock();
345 >        Thread t1 = new Thread(new CheckedRunnable() {
346 >            public void realRun() {
347 >                lock.readLock().lock();
348 >                lock.readLock().unlock();
349 >            }});
350 >        Thread t2 = new Thread(new CheckedRunnable() {
351 >            public void realRun() {
352 >                lock.readLock().lock();
353 >                lock.readLock().unlock();
354 >            }});
355  
356          t1.start();
357          t2.start();
# Line 386 | Line 367 | public class ReentrantReadWriteLockTest
367       * Read trylock succeeds if write locked by current thread
368       */
369      public void testReadHoldingWriteLock() {
370 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
371 <        lock.writeLock().lock();
370 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
371 >        lock.writeLock().lock();
372          assertTrue(lock.readLock().tryLock());
373          lock.readLock().unlock();
374          lock.writeLock().unlock();
# Line 398 | Line 379 | public class ReentrantReadWriteLockTest
379       * other threads are waiting for readlock
380       */
381      public void testReadHoldingWriteLock2() throws InterruptedException {
382 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
383 <        lock.writeLock().lock();
384 <        Thread t1 = new Thread(new Runnable() {
385 <                public void run() {
386 <                    lock.readLock().lock();
387 <                    lock.readLock().unlock();
388 <                }
389 <            });
390 <        Thread t2 = new Thread(new Runnable() {
391 <                public void run() {
392 <                    lock.readLock().lock();
393 <                    lock.readLock().unlock();
413 <                }
414 <            });
382 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
383 >        lock.writeLock().lock();
384 >        Thread t1 = new Thread(new CheckedRunnable() {
385 >            public void realRun() {
386 >                lock.readLock().lock();
387 >                lock.readLock().unlock();
388 >            }});
389 >        Thread t2 = new Thread(new CheckedRunnable() {
390 >            public void realRun() {
391 >                lock.readLock().lock();
392 >                lock.readLock().unlock();
393 >            }});
394  
395          t1.start();
396          t2.start();
# Line 432 | Line 411 | public class ReentrantReadWriteLockTest
411       * other threads are waiting for writelock
412       */
413      public void testReadHoldingWriteLock3() throws InterruptedException {
414 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
415 <        lock.writeLock().lock();
416 <        Thread t1 = new Thread(new Runnable() {
417 <                public void run() {
418 <                    lock.writeLock().lock();
419 <                    lock.writeLock().unlock();
420 <                }
421 <            });
422 <        Thread t2 = new Thread(new Runnable() {
423 <                public void run() {
424 <                    lock.writeLock().lock();
425 <                    lock.writeLock().unlock();
447 <                }
448 <            });
414 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
415 >        lock.writeLock().lock();
416 >        Thread t1 = new Thread(new CheckedRunnable() {
417 >            public void realRun() {
418 >                lock.writeLock().lock();
419 >                lock.writeLock().unlock();
420 >            }});
421 >        Thread t2 = new Thread(new CheckedRunnable() {
422 >            public void realRun() {
423 >                lock.writeLock().lock();
424 >                lock.writeLock().unlock();
425 >            }});
426  
427          t1.start();
428          t2.start();
# Line 467 | Line 444 | public class ReentrantReadWriteLockTest
444       * other threads are waiting for writelock
445       */
446      public void testWriteHoldingWriteLock4() throws InterruptedException {
447 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
448 <        lock.writeLock().lock();
449 <        Thread t1 = new Thread(new Runnable() {
450 <                public void run() {
451 <                    lock.writeLock().lock();
452 <                    lock.writeLock().unlock();
453 <                }
454 <            });
455 <        Thread t2 = new Thread(new Runnable() {
456 <                public void run() {
457 <                    lock.writeLock().lock();
458 <                    lock.writeLock().unlock();
482 <                }
483 <            });
447 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
448 >        lock.writeLock().lock();
449 >        Thread t1 = new Thread(new CheckedRunnable() {
450 >            public void realRun() {
451 >                lock.writeLock().lock();
452 >                lock.writeLock().unlock();
453 >            }});
454 >        Thread t2 = new Thread(new CheckedRunnable() {
455 >            public void realRun() {
456 >                lock.writeLock().lock();
457 >                lock.writeLock().unlock();
458 >            }});
459  
460          t1.start();
461          t2.start();
# Line 501 | Line 476 | public class ReentrantReadWriteLockTest
476       * Fair Read trylock succeeds if write locked by current thread
477       */
478      public void testReadHoldingWriteLockFair() {
479 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true);
480 <        lock.writeLock().lock();
479 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true);
480 >        lock.writeLock().lock();
481          assertTrue(lock.readLock().tryLock());
482          lock.readLock().unlock();
483          lock.writeLock().unlock();
# Line 513 | Line 488 | public class ReentrantReadWriteLockTest
488       * other threads are waiting for readlock
489       */
490      public void testReadHoldingWriteLockFair2() throws InterruptedException {
491 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true);
492 <        lock.writeLock().lock();
493 <        Thread t1 = new Thread(new Runnable() {
494 <                public void run() {
495 <                    lock.readLock().lock();
496 <                    lock.readLock().unlock();
497 <                }
498 <            });
499 <        Thread t2 = new Thread(new Runnable() {
500 <                public void run() {
501 <                    lock.readLock().lock();
502 <                    lock.readLock().unlock();
528 <                }
529 <            });
491 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true);
492 >        lock.writeLock().lock();
493 >        Thread t1 = new Thread(new CheckedRunnable() {
494 >            public void realRun() {
495 >                lock.readLock().lock();
496 >                lock.readLock().unlock();
497 >            }});
498 >        Thread t2 = new Thread(new CheckedRunnable() {
499 >            public void realRun() {
500 >                lock.readLock().lock();
501 >                lock.readLock().unlock();
502 >            }});
503  
504          t1.start();
505          t2.start();
# Line 548 | Line 521 | public class ReentrantReadWriteLockTest
521       * other threads are waiting for writelock
522       */
523      public void testReadHoldingWriteLockFair3() throws InterruptedException {
524 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true);
525 <        lock.writeLock().lock();
526 <        Thread t1 = new Thread(new Runnable() {
527 <                public void run() {
528 <                    lock.writeLock().lock();
529 <                    lock.writeLock().unlock();
530 <                }
531 <            });
532 <        Thread t2 = new Thread(new Runnable() {
533 <                public void run() {
534 <                    lock.writeLock().lock();
535 <                    lock.writeLock().unlock();
563 <                }
564 <            });
524 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true);
525 >        lock.writeLock().lock();
526 >        Thread t1 = new Thread(new CheckedRunnable() {
527 >            public void realRun() {
528 >                lock.writeLock().lock();
529 >                lock.writeLock().unlock();
530 >            }});
531 >        Thread t2 = new Thread(new CheckedRunnable() {
532 >            public void realRun() {
533 >                lock.writeLock().lock();
534 >                lock.writeLock().unlock();
535 >            }});
536  
537          t1.start();
538          t2.start();
# Line 583 | Line 554 | public class ReentrantReadWriteLockTest
554       * other threads are waiting for writelock
555       */
556      public void testWriteHoldingWriteLockFair4() throws InterruptedException {
557 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true);
558 <        lock.writeLock().lock();
559 <        Thread t1 = new Thread(new Runnable() {
560 <                public void run() {
561 <                    lock.writeLock().lock();
562 <                    lock.writeLock().unlock();
563 <                }
564 <            });
565 <        Thread t2 = new Thread(new Runnable() {
566 <                public void run() {
567 <                    lock.writeLock().lock();
568 <                    lock.writeLock().unlock();
598 <                }
599 <            });
557 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true);
558 >        lock.writeLock().lock();
559 >        Thread t1 = new Thread(new CheckedRunnable() {
560 >            public void realRun() {
561 >                lock.writeLock().lock();
562 >                lock.writeLock().unlock();
563 >            }});
564 >        Thread t2 = new Thread(new CheckedRunnable() {
565 >            public void realRun() {
566 >                lock.writeLock().lock();
567 >                lock.writeLock().unlock();
568 >            }});
569  
570          t1.start();
571          t2.start();
# Line 620 | Line 589 | public class ReentrantReadWriteLockTest
589       * Read tryLock succeeds if readlocked but not writelocked
590       */
591      public void testTryLockWhenReadLocked() throws InterruptedException {
592 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
593 <        lock.readLock().lock();
594 <        Thread t = new Thread(new Runnable() {
595 <                public void run() {
596 <                    threadAssertTrue(lock.readLock().tryLock());
597 <                    lock.readLock().unlock();
598 <                }
630 <            });
592 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
593 >        lock.readLock().lock();
594 >        Thread t = new Thread(new CheckedRunnable() {
595 >            public void realRun() {
596 >                threadAssertTrue(lock.readLock().tryLock());
597 >                lock.readLock().unlock();
598 >            }});
599  
600          t.start();
601          t.join();
# Line 640 | Line 608 | public class ReentrantReadWriteLockTest
608       * write tryLock fails when readlocked
609       */
610      public void testWriteTryLockWhenReadLocked() throws InterruptedException {
611 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
612 <        lock.readLock().lock();
613 <        Thread t = new Thread(new Runnable() {
614 <                public void run() {
615 <                    threadAssertFalse(lock.writeLock().tryLock());
616 <                }
649 <            });
611 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
612 >        lock.readLock().lock();
613 >        Thread t = new Thread(new CheckedRunnable() {
614 >            public void realRun() {
615 >                threadAssertFalse(lock.writeLock().tryLock());
616 >            }});
617  
618          t.start();
619          t.join();
# Line 658 | Line 625 | public class ReentrantReadWriteLockTest
625       * Fair Read tryLock succeeds if readlocked but not writelocked
626       */
627      public void testTryLockWhenReadLockedFair() throws InterruptedException {
628 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true);
629 <        lock.readLock().lock();
630 <        Thread t = new Thread(new Runnable() {
631 <                public void run() {
632 <                    threadAssertTrue(lock.readLock().tryLock());
633 <                    lock.readLock().unlock();
634 <                }
668 <            });
628 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true);
629 >        lock.readLock().lock();
630 >        Thread t = new Thread(new CheckedRunnable() {
631 >            public void realRun() {
632 >                threadAssertTrue(lock.readLock().tryLock());
633 >                lock.readLock().unlock();
634 >            }});
635  
636          t.start();
637          t.join();
# Line 678 | Line 644 | public class ReentrantReadWriteLockTest
644       * Fair write tryLock fails when readlocked
645       */
646      public void testWriteTryLockWhenReadLockedFair() throws InterruptedException {
647 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true);
648 <        lock.readLock().lock();
649 <        Thread t = new Thread(new Runnable() {
650 <                public void run() {
651 <                    threadAssertFalse(lock.writeLock().tryLock());
652 <                }
687 <            });
647 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true);
648 >        lock.readLock().lock();
649 >        Thread t = new Thread(new CheckedRunnable() {
650 >            public void realRun() {
651 >                threadAssertFalse(lock.writeLock().tryLock());
652 >            }});
653  
654          t.start();
655          t.join();
# Line 697 | Line 662 | public class ReentrantReadWriteLockTest
662       * write timed tryLock times out if locked
663       */
664      public void testWriteTryLock_Timeout() throws InterruptedException {
665 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
666 <        lock.writeLock().lock();
667 <        Thread t = new Thread(new Runnable() {
668 <                public void run() {
669 <                    try {
670 <                        threadAssertFalse(lock.writeLock().tryLock(1, TimeUnit.MILLISECONDS));
706 <                    } catch (Exception ex) {
707 <                        threadUnexpectedException();
708 <                    }
709 <                }
710 <            });
665 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
666 >        lock.writeLock().lock();
667 >        Thread t = new Thread(new CheckedRunnable() {
668 >            public void realRun() throws InterruptedException {
669 >                threadAssertFalse(lock.writeLock().tryLock(1, MILLISECONDS));
670 >            }});
671  
672          t.start();
673          t.join();
674 +        assertTrue(lock.writeLock().isHeldByCurrentThread());
675          lock.writeLock().unlock();
676      }
677  
# Line 718 | Line 679 | public class ReentrantReadWriteLockTest
679       * read timed tryLock times out if write-locked
680       */
681      public void testReadTryLock_Timeout() throws InterruptedException {
682 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
683 <        lock.writeLock().lock();
684 <        Thread t = new Thread(new Runnable() {
685 <                public void run() {
686 <                    try {
687 <                        threadAssertFalse(lock.readLock().tryLock(1, TimeUnit.MILLISECONDS));
727 <                    } catch (Exception ex) {
728 <                        threadUnexpectedException();
729 <                    }
730 <                }
731 <            });
682 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
683 >        lock.writeLock().lock();
684 >        Thread t = new Thread(new CheckedRunnable() {
685 >            public void realRun() throws InterruptedException {
686 >                threadAssertFalse(lock.readLock().tryLock(1, MILLISECONDS));
687 >            }});
688  
689          t.start();
690          t.join();
691 +        assertTrue(lock.writeLock().isHeldByCurrentThread());
692          lock.writeLock().unlock();
693      }
694  
# Line 740 | Line 697 | public class ReentrantReadWriteLockTest
697       * write lockInterruptibly succeeds if lock free else is interruptible
698       */
699      public void testWriteLockInterruptibly() throws InterruptedException {
700 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
700 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
701          lock.writeLock().lockInterruptibly();
702 <        Thread t = new Thread(new Runnable() {
703 <                public void run() {
704 <                    try {
705 <                        lock.writeLock().lockInterruptibly();
749 <                        threadShouldThrow();
750 <                    }
751 <                    catch (InterruptedException success) {
752 <                    }
753 <                }
754 <            });
702 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
703 >            public void realRun() throws InterruptedException {
704 >                lock.writeLock().lockInterruptibly();
705 >            }});
706  
707          t.start();
708          Thread.sleep(SHORT_DELAY_MS);
# Line 765 | Line 716 | public class ReentrantReadWriteLockTest
716       *  read lockInterruptibly succeeds if lock free else is interruptible
717       */
718      public void testReadLockInterruptibly() throws InterruptedException {
719 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
719 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
720          lock.writeLock().lockInterruptibly();
721 <        Thread t = new Thread(new Runnable() {
722 <                public void run() {
723 <                    try {
724 <                        lock.readLock().lockInterruptibly();
774 <                        threadShouldThrow();
775 <                    }
776 <                    catch (InterruptedException success) {
777 <                    }
778 <                }
779 <            });
721 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
722 >            public void realRun() throws InterruptedException {
723 >                lock.readLock().lockInterruptibly();
724 >            }});
725  
726          t.start();
727          Thread.sleep(SHORT_DELAY_MS);
# Line 789 | Line 734 | public class ReentrantReadWriteLockTest
734       * Calling await without holding lock throws IllegalMonitorStateException
735       */
736      public void testAwait_IllegalMonitor() throws InterruptedException {
737 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
737 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
738          final Condition c = lock.writeLock().newCondition();
739          try {
740              c.await();
# Line 801 | Line 746 | public class ReentrantReadWriteLockTest
746       * Calling signal without holding lock throws IllegalMonitorStateException
747       */
748      public void testSignal_IllegalMonitor() {
749 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
749 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
750          final Condition c = lock.writeLock().newCondition();
751          try {
752              c.signal();
# Line 813 | Line 758 | public class ReentrantReadWriteLockTest
758       * awaitNanos without a signal times out
759       */
760      public void testAwaitNanos_Timeout() throws InterruptedException {
761 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
761 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
762          final Condition c = lock.writeLock().newCondition();
763  
764          lock.writeLock().lock();
# Line 826 | Line 771 | public class ReentrantReadWriteLockTest
771      /**
772       *  timed await without a signal times out
773       */
774 <    public void testAwait_Timeout() {
775 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
774 >    public void testAwait_Timeout() throws InterruptedException {
775 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
776          final Condition c = lock.writeLock().newCondition();
777          lock.writeLock().lock();
778 +        assertFalse(c.await(SHORT_DELAY_MS, MILLISECONDS));
779          lock.writeLock().unlock();
780      }
781  
782      /**
783       * awaitUntil without a signal times out
784       */
785 <    public void testAwaitUntil_Timeout() {
786 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
785 >    public void testAwaitUntil_Timeout() throws InterruptedException {
786 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
787          final Condition c = lock.writeLock().newCondition();
788          lock.writeLock().lock();
789          java.util.Date d = new java.util.Date();
790 +        assertFalse(c.awaitUntil(new java.util.Date(d.getTime() + 10)));
791          lock.writeLock().unlock();
792      }
793  
# Line 848 | Line 795 | public class ReentrantReadWriteLockTest
795       * await returns when signalled
796       */
797      public void testAwait() throws InterruptedException {
798 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
798 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
799          final Condition c = lock.writeLock().newCondition();
800 <        Thread t = new Thread(new Runnable() {
801 <                public void run() {
802 <                    try {
803 <                        lock.writeLock().lock();
804 <                        c.await();
805 <                        lock.writeLock().unlock();
859 <                    }
860 <                    catch (InterruptedException e) {
861 <                        threadUnexpectedException();
862 <                    }
863 <                }
864 <            });
800 >        Thread t = new Thread(new CheckedRunnable() {
801 >            public void realRun() throws InterruptedException {
802 >                lock.writeLock().lock();
803 >                c.await();
804 >                lock.writeLock().unlock();
805 >            }});
806  
807          t.start();
808          Thread.sleep(SHORT_DELAY_MS);
# Line 931 | Line 872 | public class ReentrantReadWriteLockTest
872       * await is interruptible
873       */
874      public void testAwait_Interrupt() throws InterruptedException {
875 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
875 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
876          final Condition c = lock.writeLock().newCondition();
877 <        Thread t = new Thread(new Runnable() {
878 <                public void run() {
879 <                    try {
880 <                        lock.writeLock().lock();
881 <                        c.await();
882 <                        lock.writeLock().unlock();
942 <                        threadShouldThrow();
943 <                    }
944 <                    catch (InterruptedException success) {
945 <                    }
946 <                }
947 <            });
877 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
878 >            public void realRun() throws InterruptedException {
879 >                lock.writeLock().lock();
880 >                c.await();
881 >                lock.writeLock().unlock();
882 >            }});
883  
884          t.start();
885          Thread.sleep(SHORT_DELAY_MS);
# Line 957 | Line 892 | public class ReentrantReadWriteLockTest
892       * awaitNanos is interruptible
893       */
894      public void testAwaitNanos_Interrupt() throws InterruptedException {
895 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
895 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
896          final Condition c = lock.writeLock().newCondition();
897 <        Thread t = new Thread(new Runnable() {
898 <                public void run() {
899 <                    try {
900 <                        lock.writeLock().lock();
901 <                        c.awaitNanos(SHORT_DELAY_MS * 2 * 1000000);
902 <                        lock.writeLock().unlock();
968 <                        threadShouldThrow();
969 <                    }
970 <                    catch (InterruptedException success) {
971 <                    }
972 <                }
973 <            });
897 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
898 >            public void realRun() throws InterruptedException {
899 >                lock.writeLock().lock();
900 >                c.awaitNanos(SHORT_DELAY_MS * 2 * 1000000);
901 >                lock.writeLock().unlock();
902 >            }});
903  
904          t.start();
905          Thread.sleep(SHORT_DELAY_MS);
# Line 983 | Line 912 | public class ReentrantReadWriteLockTest
912       * awaitUntil is interruptible
913       */
914      public void testAwaitUntil_Interrupt() throws InterruptedException {
915 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
915 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
916          final Condition c = lock.writeLock().newCondition();
917 <        Thread t = new Thread(new Runnable() {
918 <                public void run() {
919 <                    try {
920 <                        lock.writeLock().lock();
921 <                        java.util.Date d = new java.util.Date();
922 <                        c.awaitUntil(new java.util.Date(d.getTime() + 10000));
923 <                        lock.writeLock().unlock();
995 <                        threadShouldThrow();
996 <                    }
997 <                    catch (InterruptedException success) {
998 <                    }
999 <                }
1000 <            });
917 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
918 >            public void realRun() throws InterruptedException {
919 >                lock.writeLock().lock();
920 >                java.util.Date d = new java.util.Date();
921 >                c.awaitUntil(new java.util.Date(d.getTime() + 10000));
922 >                lock.writeLock().unlock();
923 >            }});
924  
925          t.start();
926          Thread.sleep(SHORT_DELAY_MS);
# Line 1010 | Line 933 | public class ReentrantReadWriteLockTest
933       * signalAll wakes up all threads
934       */
935      public void testSignalAll() throws InterruptedException {
936 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
936 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
937          final Condition c = lock.writeLock().newCondition();
938 <        Thread t1 = new Thread(new Runnable() {
939 <                public void run() {
940 <                    try {
941 <                        lock.writeLock().lock();
942 <                        c.await();
943 <                        lock.writeLock().unlock();
944 <                    }
945 <                    catch (InterruptedException e) {
946 <                        threadUnexpectedException();
947 <                    }
948 <                }
949 <            });
950 <
1028 <        Thread t2 = new Thread(new Runnable() {
1029 <                public void run() {
1030 <                    try {
1031 <                        lock.writeLock().lock();
1032 <                        c.await();
1033 <                        lock.writeLock().unlock();
1034 <                    }
1035 <                    catch (InterruptedException e) {
1036 <                        threadUnexpectedException();
1037 <                    }
1038 <                }
1039 <            });
938 >        Thread t1 = new Thread(new CheckedRunnable() {
939 >            public void realRun() throws InterruptedException {
940 >                lock.writeLock().lock();
941 >                c.await();
942 >                lock.writeLock().unlock();
943 >            }});
944 >
945 >        Thread t2 = new Thread(new CheckedRunnable() {
946 >            public void realRun() throws InterruptedException {
947 >                lock.writeLock().lock();
948 >                c.await();
949 >                lock.writeLock().unlock();
950 >            }});
951  
952          t1.start();
953          t2.start();
# Line 1074 | Line 985 | public class ReentrantReadWriteLockTest
985       * hasQueuedThreads reports whether there are waiting threads
986       */
987      public void testhasQueuedThreads() throws InterruptedException {
988 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
988 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
989          Thread t1 = new Thread(new InterruptedLockRunnable(lock));
990          Thread t2 = new Thread(new InterruptibleLockRunnable(lock));
991          assertFalse(lock.hasQueuedThreads());
# Line 1099 | Line 1010 | public class ReentrantReadWriteLockTest
1010       * hasQueuedThread(null) throws NPE
1011       */
1012      public void testHasQueuedThreadNPE() {
1013 <        final ReentrantReadWriteLock sync = new ReentrantReadWriteLock();
1013 >        final ReentrantReadWriteLock sync = new ReentrantReadWriteLock();
1014          try {
1015              sync.hasQueuedThread(null);
1016              shouldThrow();
1017 <        } catch (NullPointerException success) {
1107 <        }
1017 >        } catch (NullPointerException success) {}
1018      }
1019  
1020      /**
1021       * hasQueuedThread reports whether a thread is queued.
1022       */
1023      public void testHasQueuedThread() throws InterruptedException {
1024 <        final ReentrantReadWriteLock sync = new ReentrantReadWriteLock();
1024 >        final ReentrantReadWriteLock sync = new ReentrantReadWriteLock();
1025          Thread t1 = new Thread(new InterruptedLockRunnable(sync));
1026          Thread t2 = new Thread(new InterruptibleLockRunnable(sync));
1027          assertFalse(sync.hasQueuedThread(t1));
# Line 1142 | Line 1052 | public class ReentrantReadWriteLockTest
1052       * getQueueLength reports number of waiting threads
1053       */
1054      public void testGetQueueLength() throws InterruptedException {
1055 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
1055 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
1056          Thread t1 = new Thread(new InterruptedLockRunnable(lock));
1057          Thread t2 = new Thread(new InterruptibleLockRunnable(lock));
1058          assertEquals(0, lock.getQueueLength());
# Line 1167 | Line 1077 | public class ReentrantReadWriteLockTest
1077       * getQueuedThreads includes waiting threads
1078       */
1079      public void testGetQueuedThreads() throws InterruptedException {
1080 <        final PublicReentrantReadWriteLock lock = new PublicReentrantReadWriteLock();
1080 >        final PublicReentrantReadWriteLock lock = new PublicReentrantReadWriteLock();
1081          Thread t1 = new Thread(new InterruptedLockRunnable(lock));
1082          Thread t2 = new Thread(new InterruptibleLockRunnable(lock));
1083          assertTrue(lock.getQueuedThreads().isEmpty());
# Line 1195 | Line 1105 | public class ReentrantReadWriteLockTest
1105       * hasWaiters throws NPE if null
1106       */
1107      public void testHasWaitersNPE() {
1108 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
1108 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
1109          try {
1110              lock.hasWaiters(null);
1111              shouldThrow();
# Line 1206 | Line 1116 | public class ReentrantReadWriteLockTest
1116       * getWaitQueueLength throws NPE if null
1117       */
1118      public void testGetWaitQueueLengthNPE() {
1119 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
1119 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
1120          try {
1121              lock.getWaitQueueLength(null);
1122              shouldThrow();
# Line 1218 | Line 1128 | public class ReentrantReadWriteLockTest
1128       * getWaitingThreads throws NPE if null
1129       */
1130      public void testGetWaitingThreadsNPE() {
1131 <        final PublicReentrantReadWriteLock lock = new PublicReentrantReadWriteLock();
1131 >        final PublicReentrantReadWriteLock lock = new PublicReentrantReadWriteLock();
1132          try {
1133              lock.getWaitingThreads(null);
1134              shouldThrow();
# Line 1229 | Line 1139 | public class ReentrantReadWriteLockTest
1139       * hasWaiters throws IAE if not owned
1140       */
1141      public void testHasWaitersIAE() {
1142 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
1142 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
1143          final Condition c = lock.writeLock().newCondition();
1144 <        final ReentrantReadWriteLock lock2 = new ReentrantReadWriteLock();
1144 >        final ReentrantReadWriteLock lock2 = new ReentrantReadWriteLock();
1145          try {
1146              lock2.hasWaiters(c);
1147              shouldThrow();
# Line 1242 | Line 1152 | public class ReentrantReadWriteLockTest
1152       * hasWaiters throws IMSE if not locked
1153       */
1154      public void testHasWaitersIMSE() {
1155 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
1155 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
1156          final Condition c = lock.writeLock().newCondition();
1157          try {
1158              lock.hasWaiters(c);
# Line 1255 | Line 1165 | public class ReentrantReadWriteLockTest
1165       * getWaitQueueLength throws IAE if not owned
1166       */
1167      public void testGetWaitQueueLengthIAE() {
1168 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
1168 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
1169          final Condition c = lock.writeLock().newCondition();
1170 <        final ReentrantReadWriteLock lock2 = new ReentrantReadWriteLock();
1170 >        final ReentrantReadWriteLock lock2 = new ReentrantReadWriteLock();
1171          try {
1172              lock2.getWaitQueueLength(c);
1173              shouldThrow();
# Line 1268 | Line 1178 | public class ReentrantReadWriteLockTest
1178       * getWaitQueueLength throws IMSE if not locked
1179       */
1180      public void testGetWaitQueueLengthIMSE() {
1181 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
1181 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
1182          final Condition c = lock.writeLock().newCondition();
1183          try {
1184              lock.getWaitQueueLength(c);
# Line 1281 | Line 1191 | public class ReentrantReadWriteLockTest
1191       * getWaitingThreads throws IAE if not owned
1192       */
1193      public void testGetWaitingThreadsIAE() {
1194 <        final PublicReentrantReadWriteLock lock = new PublicReentrantReadWriteLock();
1194 >        final PublicReentrantReadWriteLock lock = new PublicReentrantReadWriteLock();
1195          final Condition c = lock.writeLock().newCondition();
1196 <        final PublicReentrantReadWriteLock lock2 = new PublicReentrantReadWriteLock();
1196 >        final PublicReentrantReadWriteLock lock2 = new PublicReentrantReadWriteLock();
1197          try {
1198              lock2.getWaitingThreads(c);
1199              shouldThrow();
# Line 1294 | Line 1204 | public class ReentrantReadWriteLockTest
1204       * getWaitingThreads throws IMSE if not locked
1205       */
1206      public void testGetWaitingThreadsIMSE() {
1207 <        final PublicReentrantReadWriteLock lock = new PublicReentrantReadWriteLock();
1207 >        final PublicReentrantReadWriteLock lock = new PublicReentrantReadWriteLock();
1208          final Condition c = lock.writeLock().newCondition();
1209          try {
1210              lock.getWaitingThreads(c);
# Line 1307 | Line 1217 | public class ReentrantReadWriteLockTest
1217       * hasWaiters returns true when a thread is waiting, else false
1218       */
1219      public void testHasWaiters() throws InterruptedException {
1220 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
1220 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
1221          final Condition c = lock.writeLock().newCondition();
1222 <        Thread t = new Thread(new Runnable() {
1223 <                public void run() {
1224 <                    try {
1225 <                        lock.writeLock().lock();
1226 <                        threadAssertFalse(lock.hasWaiters(c));
1227 <                        threadAssertEquals(0, lock.getWaitQueueLength(c));
1228 <                        c.await();
1229 <                        lock.writeLock().unlock();
1320 <                    }
1321 <                    catch (InterruptedException e) {
1322 <                        threadUnexpectedException();
1323 <                    }
1324 <                }
1325 <            });
1222 >        Thread t = new Thread(new CheckedRunnable() {
1223 >            public void realRun() throws InterruptedException {
1224 >                lock.writeLock().lock();
1225 >                threadAssertFalse(lock.hasWaiters(c));
1226 >                threadAssertEquals(0, lock.getWaitQueueLength(c));
1227 >                c.await();
1228 >                lock.writeLock().unlock();
1229 >            }});
1230  
1231          t.start();
1232          Thread.sleep(SHORT_DELAY_MS);
# Line 1344 | Line 1248 | public class ReentrantReadWriteLockTest
1248       * getWaitQueueLength returns number of waiting threads
1249       */
1250      public void testGetWaitQueueLength() throws InterruptedException {
1251 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
1251 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
1252          final Condition c = lock.writeLock().newCondition();
1253 <        Thread t = new Thread(new Runnable() {
1254 <                public void run() {
1255 <                    try {
1256 <                        lock.writeLock().lock();
1257 <                        threadAssertFalse(lock.hasWaiters(c));
1258 <                        threadAssertEquals(0, lock.getWaitQueueLength(c));
1259 <                        c.await();
1260 <                        lock.writeLock().unlock();
1357 <                    }
1358 <                    catch (InterruptedException e) {
1359 <                        threadUnexpectedException();
1360 <                    }
1361 <                }
1362 <            });
1253 >        Thread t = new Thread(new CheckedRunnable() {
1254 >            public void realRun() throws InterruptedException {
1255 >                lock.writeLock().lock();
1256 >                threadAssertFalse(lock.hasWaiters(c));
1257 >                threadAssertEquals(0, lock.getWaitQueueLength(c));
1258 >                c.await();
1259 >                lock.writeLock().unlock();
1260 >            }});
1261  
1262          t.start();
1263          Thread.sleep(SHORT_DELAY_MS);
# Line 1382 | Line 1280 | public class ReentrantReadWriteLockTest
1280       * getWaitingThreads returns only and all waiting threads
1281       */
1282      public void testGetWaitingThreads() throws InterruptedException {
1283 <        final PublicReentrantReadWriteLock lock = new PublicReentrantReadWriteLock();
1283 >        final PublicReentrantReadWriteLock lock = new PublicReentrantReadWriteLock();
1284          final Condition c = lock.writeLock().newCondition();
1285 <        Thread t1 = new Thread(new Runnable() {
1286 <                public void run() {
1287 <                    try {
1288 <                        lock.writeLock().lock();
1289 <                        threadAssertTrue(lock.getWaitingThreads(c).isEmpty());
1290 <                        c.await();
1291 <                        lock.writeLock().unlock();
1292 <                    }
1293 <                    catch (InterruptedException e) {
1294 <                        threadUnexpectedException();
1295 <                    }
1296 <                }
1297 <            });
1298 <
1299 <        Thread t2 = new Thread(new Runnable() {
1402 <                public void run() {
1403 <                    try {
1404 <                        lock.writeLock().lock();
1405 <                        threadAssertFalse(lock.getWaitingThreads(c).isEmpty());
1406 <                        c.await();
1407 <                        lock.writeLock().unlock();
1408 <                    }
1409 <                    catch (InterruptedException e) {
1410 <                        threadUnexpectedException();
1411 <                    }
1412 <                }
1413 <            });
1285 >        Thread t1 = new Thread(new CheckedRunnable() {
1286 >            public void realRun() throws InterruptedException {
1287 >                lock.writeLock().lock();
1288 >                threadAssertTrue(lock.getWaitingThreads(c).isEmpty());
1289 >                c.await();
1290 >                lock.writeLock().unlock();
1291 >            }});
1292 >
1293 >        Thread t2 = new Thread(new CheckedRunnable() {
1294 >            public void realRun() throws InterruptedException {
1295 >                lock.writeLock().lock();
1296 >                threadAssertFalse(lock.getWaitingThreads(c).isEmpty());
1297 >                c.await();
1298 >                lock.writeLock().unlock();
1299 >            }});
1300  
1301          lock.writeLock().lock();
1302          assertTrue(lock.getWaitingThreads(c).isEmpty());

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines