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.36 by jsr166, Sat Nov 21 02:33:20 2009 UTC vs.
Revision 1.37 by jsr166, Sat Nov 21 10:25:05 2009 UTC

# Line 266 | Line 266 | public class ReentrantReadWriteLockTest
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 <                }
273 <            });
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 283 | Line 282 | public class ReentrantReadWriteLockTest
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 <                }
290 <            });
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 300 | Line 298 | public class ReentrantReadWriteLockTest
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 <                }
308 <            });
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 318 | Line 315 | public class ReentrantReadWriteLockTest
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();
331 <                }
332 <            });
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 347 | Line 342 | public class ReentrantReadWriteLockTest
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();
360 <                }
361 <            });
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 388 | Line 381 | public class ReentrantReadWriteLockTest
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();
401 <                }
402 <            });
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 422 | Line 413 | public class ReentrantReadWriteLockTest
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();
435 <                }
436 <            });
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 457 | Line 446 | public class ReentrantReadWriteLockTest
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();
470 <                }
471 <            });
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 503 | Line 490 | public class ReentrantReadWriteLockTest
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();
516 <                }
517 <            });
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 538 | Line 523 | public class ReentrantReadWriteLockTest
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();
551 <                }
552 <            });
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 573 | Line 556 | public class ReentrantReadWriteLockTest
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();
586 <                }
587 <            });
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 610 | Line 591 | public class ReentrantReadWriteLockTest
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 <                }
618 <            });
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 630 | Line 610 | public class ReentrantReadWriteLockTest
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 <                }
637 <            });
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 648 | Line 627 | public class ReentrantReadWriteLockTest
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 <                }
656 <            });
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 668 | Line 646 | public class ReentrantReadWriteLockTest
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 <                }
675 <            });
649 >        Thread t = new Thread(new CheckedRunnable() {
650 >            public void realRun() {
651 >                threadAssertFalse(lock.writeLock().tryLock());
652 >            }});
653  
654          t.start();
655          t.join();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines