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.35 by jsr166, Sat Nov 21 02:07:27 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  
# Line 214 | Line 215 | public class ReentrantReadWriteLockTest
215          lock.writeLock().lock();
216          Thread t = new Thread(new CheckedInterruptedRunnable() {
217              public void realRun() throws InterruptedException {
218 <                lock.writeLock().tryLock(1000,TimeUnit.MILLISECONDS);
218 >                lock.writeLock().tryLock(1000,MILLISECONDS);
219              }});
220  
221          t.start();
# Line 250 | Line 251 | public class ReentrantReadWriteLockTest
251          lock.writeLock().lock();
252          Thread t = new Thread(new CheckedInterruptedRunnable() {
253              public void realRun() throws InterruptedException {
254 <                lock.readLock().tryLock(1000,TimeUnit.MILLISECONDS);
254 >                lock.readLock().tryLock(1000,MILLISECONDS);
255              }});
256  
257          t.start();
# Line 265 | 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 <                }
272 <            });
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 282 | 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 <                }
289 <            });
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 299 | 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 <                }
307 <            });
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 317 | 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();
330 <                }
331 <            });
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 346 | 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();
359 <                }
360 <            });
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 387 | 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();
400 <                }
401 <            });
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 421 | 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();
434 <                }
435 <            });
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 456 | 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();
469 <                }
470 <            });
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 502 | 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();
515 <                }
516 <            });
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 537 | 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();
550 <                }
551 <            });
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 572 | 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();
585 <                }
586 <            });
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 609 | 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 <                }
617 <            });
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 629 | 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 <                }
636 <            });
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 647 | 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 <                }
655 <            });
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 667 | 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 <                }
674 <            });
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 688 | Line 666 | public class ReentrantReadWriteLockTest
666          lock.writeLock().lock();
667          Thread t = new Thread(new CheckedRunnable() {
668              public void realRun() throws InterruptedException {
669 <                threadAssertFalse(lock.writeLock().tryLock(1, TimeUnit.MILLISECONDS));
669 >                threadAssertFalse(lock.writeLock().tryLock(1, MILLISECONDS));
670              }});
671  
672          t.start();
# Line 705 | Line 683 | public class ReentrantReadWriteLockTest
683          lock.writeLock().lock();
684          Thread t = new Thread(new CheckedRunnable() {
685              public void realRun() throws InterruptedException {
686 <                threadAssertFalse(lock.readLock().tryLock(1, TimeUnit.MILLISECONDS));
686 >                threadAssertFalse(lock.readLock().tryLock(1, MILLISECONDS));
687              }});
688  
689          t.start();
# Line 797 | Line 775 | public class ReentrantReadWriteLockTest
775          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
776          final Condition c = lock.writeLock().newCondition();
777          lock.writeLock().lock();
778 <        assertFalse(c.await(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
778 >        assertFalse(c.await(SHORT_DELAY_MS, MILLISECONDS));
779          lock.writeLock().unlock();
780      }
781  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines