11package  ReentrantLocks_10 ;
22
33/** 
4-  * the ReentrantLock class in Java as an alternative to synchronized code 
5-  * blocks. ReentrantLocks let you do all the stuff that you can do with 
6-  * synchronized, wait and notify, plus some more stuff besides that may come in 
4+  * the {@link java.util.concurrent.locks.ReentrantLock} class in Java as an 
5+  * alternative to synchronized code blocks. 
6+  * <br> 
7+  * {@link java.util.concurrent.locks.ReentrantLock}s let you do all the 
8+  * stuff that you can do with {@code synchronized}, {@link Object#wait()} and 
9+  * {@link Object#notify()}, plus some more stuff. Besides that may come in 
710 * handy from time to time. 
8-  * 
9-  * Source: 
11+  * <br><br>  
12+  * Source:<em>  
1013 * http://docs.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/locks/ReentrantLock.html 
11-  * 
12-  * ReentrantLock Extended capabilities include: 
13-  * 
14-  * The ability to have more than one condition variable per monitor. Monitors 
15-  * that use the synchronized keyword can only have one. This means reentrant 
16-  * locks support more than one wait()/notify() queue. The ability to make the 
17-  * lock "fair". "[fair] locks favor granting access to the longest-waiting 
14+  * </em> 
15+  * <br><br> 
16+  * {@link java.util.concurrent.locks.ReentrantLock} Extended capabilities 
17+  * include: 
18+  * <br> 
19+  * <ul> 
20+  * <li> 
21+  * The ability to have more than one {@link java.util.concurrent.locks.Condition} 
22+  * variable per monitor. 
23+  * </li> 
24+  * <li>Monitors that use the synchronized keyword can only have one. This means 
25+  * {@link java.util.concurrent.locks.ReentrantLock}s support more than one 
26+  * {@link Object#wait()}/{@link Object#notify()} queue. 
27+  * </li> 
28+  * <li> 
29+  * The ability to make the lock "fair". 
30+  * <em> 
31+  * "[fair] locks favor granting access to the longest-waiting 
1832 * thread. Otherwise this lock does not guarantee any particular access order." 
19-  * Synchronized blocks are unfair. The ability to check if the lock is being 
20-  * held. The ability to get the list of threads waiting on the lock. 
21-  * 
22-  * The disadvantages of reentrant locks are: 
23-  * 
24-  * Need to add import statement. Need to wrap lock acquisitions in a try/finally 
25-  * block. This makes it more ugly than the synchronized keyword. The 
26-  * synchronized keyword can be put in method definitions which avoids the need 
27-  * for a block which reduces nesting. For more complete comparison of 
28-  * reentrantLocks and synchronized see 
33+  * </em> 
34+  * </li> 
35+  * <li>Synchronized blocks are unfair.</li> 
36+  * <li>The ability to check if the lock is being 
37+  * held.</li> 
38+  * <li>The ability to get the list of threads waiting on the lock.</li> 
39+  * </ul> 
40+  * <br><br> 
41+  * The disadvantages of {@link java.util.concurrent.locks.ReentrantLock}s are: 
42+  * <br> 
43+  * <ul> 
44+  * <li>Need to add import statement.</li> 
45+  * <li>Need to wrap lock acquisitions in a try/finally block. This makes it more 
46+  * ugly than the synchronized keyword.</li> 
47+  * <li>The synchronized keyword can be put in method definitions which avoids 
48+  * the need for a block which reduces nesting.</li> 
49+  * </ul> 
50+  * <br><br> 
51+  * For more complete comparison of 
52+  * {@link java.util.concurrent.locks.ReentrantLock}s and {@code synchronized} 
53+  * see:<em> 
2954 * http://guruzon.com/1/concurrency/explicit-lock-locking/difference-between-synchronized-and-reentrantlock-in-java 
30-  * 
31-  * Codes with minor comments are from http://www.caveofprogramming.com/youtube/ 
55+  * </em> 
56+  * <br><br> 
57+  * Codes with minor comments are from <em>http://www.caveofprogramming.com/youtube/</em><br> 
3258 * also freely available at 
33-  * https://www.udemy.com/java-multithreading/?couponCode=FREE 
59+  * <em> https://www.udemy.com/java-multithreading/?couponCode=FREE</em>  
3460 * 
3561 * @author Z.B. Celik <[email protected] > 3662 */ 
@@ -42,8 +68,7 @@ public static void main(String[] args) throws Exception {
4268            public  void  run () {
4369                try  {
4470                    runner .firstThread ();
45-                 } catch  (InterruptedException  e ) {
46-                     e .printStackTrace ();
71+                 } catch  (InterruptedException  ignored ) {
4772                }
4873            }
4974        });
@@ -52,8 +77,7 @@ public void run() {
5277            public  void  run () {
5378                try  {
5479                    runner .secondThread ();
55-                 } catch  (InterruptedException  e ) {
56-                     e .printStackTrace ();
80+                 } catch  (InterruptedException  ignored ) {
5781                }
5882            }
5983        });
0 commit comments