|
3 | 3 | import java.util.Scanner; |
4 | 4 |
|
5 | 5 | /** |
6 | | - * Some background knowledge |
7 | | - * Source:http://www.programcreek.com/2009/02/notify-and-wait-example/ |
8 | | - * synchronized keyword is used for exclusive accessing. To make a method |
9 | | - * synchronized, simply add the synchronized keyword to its declaration. Then no |
10 | | - * two invocations of synchronized methods on the same object can interleave |
11 | | - * with each other. Synchronized statements must specify the object that |
12 | | - * provides the intrinsic lock. When synchronized(this) is used, you have to |
13 | | - * avoid to synchronizing invocations of other objects' methods. wait() tells |
| 6 | + * Some background knowledge<br> |
| 7 | + * Source: <em>http://www.programcreek.com/2009/02/notify-and-wait-example/</em> |
| 8 | + * <br><br> |
| 9 | + * {@code synchronized} keyword is used for exclusive accessing. To make a |
| 10 | + * method {@code synchronized}, simply add the {@code synchronized} keyword to its |
| 11 | + * declaration.<be> |
| 12 | + * Then no two invocations of synchronized methods on the same object can |
| 13 | + * interleave with each other. |
| 14 | + * <br> |
| 15 | + * Synchronized statements must specify the object that |
| 16 | + * provides the intrinsic lock. When {@code synchronized(this)} is used, you |
| 17 | + * have to avoid to synchronizing invocations of other objects' methods. |
| 18 | + * <br> |
| 19 | + * {@link Object#wait()} tells |
14 | 20 | * the calling thread to give up the lock and go to sleep (not polling) until |
15 | | - * some other thread enters the same lock and calls notify(). notify() wakes up |
16 | | - * the first thread that called wait() on the same object. |
17 | | - * |
18 | | - * Codes with minor comments are from http://www.caveofprogramming.com/youtube/ |
| 21 | + * some other thread enters the same lock and calls {@link Object#notify()}. |
| 22 | + * <br> |
| 23 | + * {@link Object#notify()} wakes up the first thread that called wait() on |
| 24 | + * the same object. |
| 25 | + * <br><br> |
| 26 | + * Codes with minor comments are from <em>http://www.caveofprogramming.com/youtube/</em><br> |
19 | 27 | * also freely available at |
20 | | - * https://www.udemy.com/java-multithreading/?couponCode=FREE |
| 28 | + * <em>https://www.udemy.com/java-multithreading/?couponCode=FREE</em> |
21 | 29 | * |
22 | 30 | * @author Z.B. Celik <celik.berkay@gmail.com> |
23 | 31 | */ |
24 | 32 | public class Processor { |
25 | 33 |
|
26 | | - /** |
| 34 | + /* |
27 | 35 | * public synchronized void getSomething(){ this.hello = "hello World"; } |
28 | 36 | * public void getSomething(){ synchronized(this){ this.hello = "hello |
29 | 37 | * World"; } } |
30 | 38 | * two code blocks by specification, functionally identical. |
31 | 39 | */ |
| 40 | + |
| 41 | + |
32 | 42 | public void produce() throws InterruptedException { |
33 | 43 | synchronized (this) { |
34 | 44 | System.out.println("Producer thread running ...."); |
|
0 commit comments