Skip to content

Commit 52628e5

Browse files
committed
JavaDoc optimized for packages 7.8.9
Suppress inspection Warnings about infinite loop statements
1 parent b65b85e commit 52628e5

File tree

6 files changed

+56
-45
lines changed

6 files changed

+56
-45
lines changed
Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package LowLevelProducerConsumer_9;
22

33
/**
4-
* How to implement the producer-consumer pattern using "low level" techniques;
4+
* How to implement the Producer-Consumer pattern using "low level" techniques;
55
* namely, wait, notify and synchronized. This isn't the best way to implement a
6-
* producer-consumer pattern in Java (see tutorial 7 use of BlockingQueue for
6+
* Producer-Consumer pattern in Java
7+
* (see tutorial 7 use of {@link java.util.concurrent.BlockingQueue} for
78
* the best way); but this tutorial will help you to understand how to use wait
89
* and notify.
9-
*
10-
* Codes with minor comments are from http://www.caveofprogramming.com/youtube/
10+
* <br><br>
11+
* Codes with minor comments are from <em>http://www.caveofprogramming.com/youtube/</em><br>
1112
* also freely available at
12-
* https://www.udemy.com/java-multithreading/?couponCode=FREE
13+
* <em>https://www.udemy.com/java-multithreading/?couponCode=FREE</em>
1314
*
1415
* @author Z.B. Celik <[email protected]>
1516
*/
@@ -22,9 +23,7 @@ public static void main(String[] args) throws InterruptedException {
2223
public void run() {
2324
try {
2425
processor.produce();
25-
} catch (InterruptedException e) {
26-
e.printStackTrace();
27-
}
26+
} catch (InterruptedException ignored) {}
2827
}
2928
});
3029

@@ -33,14 +32,18 @@ public void run() {
3332
public void run() {
3433
try {
3534
processor.consume();
36-
} catch (InterruptedException e) {
37-
e.printStackTrace();
38-
}
35+
} catch (InterruptedException ignored) {}
3936
}
4037
});
38+
4139
t1.start();
4240
t2.start();
43-
t1.join();
44-
t2.join();
41+
// t1.join();
42+
// t2.join();
43+
44+
// Pause for 30 seconds and force quitting the app (because we're
45+
// looping infinitely)
46+
Thread.sleep(30000);
47+
System.exit(0);
4548
}
4649
}

JavaMultiThreadingCodes/src/LowLevelProducerConsumer_9/Processor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package LowLevelProducerConsumer_9;
22

33
/**
4-
* Codes with minor comments are from http://www.caveofprogramming.com/youtube/
4+
* Codes with minor comments are from <em>http://www.caveofprogramming.com/youtube/</em><br>
55
* also freely available at
6-
* https://www.udemy.com/java-multithreading/?couponCode=FREE
6+
* <em>https://www.udemy.com/java-multithreading/?couponCode=FREE</em>
77
*
88
* @author Z.B. Celik <[email protected]>
99
*/
1010
import java.util.LinkedList;
1111
import java.util.Random;
1212

13+
@SuppressWarnings("InfiniteLoopStatement")
1314
public class Processor {
1415

1516
private LinkedList<Integer> list = new LinkedList<>();

JavaMultiThreadingCodes/src/ProducerConsumer_7/App.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.concurrent.ArrayBlockingQueue;
1919
import java.util.concurrent.BlockingQueue;
2020

21+
@SuppressWarnings("InfiniteLoopStatement")
2122
public class App {
2223

2324
/**
@@ -57,7 +58,8 @@ public void run() {
5758
// t1.join();
5859
// t2.join();
5960

60-
// Pause for 30 seconds and force quitting the app (because we're looping infinitely)
61+
// Pause for 30 seconds and force quitting the app (because we're
62+
// looping infinitely)
6163
Thread.sleep(30000);
6264
System.exit(0);
6365
}

JavaMultiThreadingCodes/src/WaitAndNotify_8/App.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package WaitAndNotify_8;
22

33
/**
4-
* wait and notify in Java; low-level multithreading methods of the Object class
4+
* {@link Object#wait()} and {@link Object#notify()} in Java; low-level
5+
* multi-threading methods of the {@link java.lang.Object} class
56
* that allow you to have one or more threads sleeping, only to be woken up by
67
* other threads at the right moment. Extremely useful for avoiding those
78
* processor-consuming "polling loops".
89
*
9-
* Codes with minor comments are from http://www.caveofprogramming.com/youtube/
10+
* Codes with minor comments are from <em>http://www.caveofprogramming.com/youtube/</em><br>
1011
* also freely available at
11-
* https://www.udemy.com/java-multithreading/?couponCode=FREE
12+
* <em>https://www.udemy.com/java-multithreading/?couponCode=FREE</em>
1213
*
1314
* @author Z.B. Celik <[email protected]>
1415
*/
@@ -21,9 +22,7 @@ public static void main(String[] args) throws InterruptedException {
2122
public void run() {
2223
try {
2324
processor.produce();
24-
} catch (InterruptedException e) {
25-
e.printStackTrace();
26-
}
25+
} catch (InterruptedException ignored) {}
2726
}
2827
});
2928

@@ -32,11 +31,10 @@ public void run() {
3231
public void run() {
3332
try {
3433
processor.consume();
35-
} catch (InterruptedException e) {
36-
e.printStackTrace();
37-
}
34+
} catch (InterruptedException ignored) {}
3835
}
3936
});
37+
4038
t1.start();
4139
t2.start();
4240
t1.join();

JavaMultiThreadingCodes/src/WaitAndNotify_8/BlockingQueueApp.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public T take() throws InterruptedException {
9898
}
9999
}
100100

101+
@SuppressWarnings("InfiniteLoopStatement")
101102
public class BlockingQueueApp {
102103

103104
public static void main(String[] args) throws InterruptedException {
@@ -109,9 +110,7 @@ public void run() {
109110
while (true) {
110111
blockingQueue.put(random.nextInt(10));
111112
}
112-
} catch (InterruptedException e) {
113-
e.printStackTrace();
114-
}
113+
} catch (InterruptedException ignored) {}
115114
}
116115
});
117116

@@ -126,9 +125,7 @@ public void run() {
126125
while (true) {
127126
blockingQueue.take();
128127
}
129-
} catch (InterruptedException e) {
130-
e.printStackTrace();
131-
}
128+
} catch (InterruptedException ignored) {}
132129
}
133130
});
134131
t1.start();

JavaMultiThreadingCodes/src/WaitAndNotify_8/Processor.java

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,42 @@
33
import java.util.Scanner;
44

55
/**
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
1420
* 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>
1927
* also freely available at
20-
* https://www.udemy.com/java-multithreading/?couponCode=FREE
28+
* <em>https://www.udemy.com/java-multithreading/?couponCode=FREE</em>
2129
*
2230
* @author Z.B. Celik <[email protected]>
2331
*/
2432
public class Processor {
2533

26-
/**
34+
/*
2735
* public synchronized void getSomething(){ this.hello = "hello World"; }
2836
* public void getSomething(){ synchronized(this){ this.hello = "hello
2937
* World"; } }
3038
* two code blocks by specification, functionally identical.
3139
*/
40+
41+
3242
public void produce() throws InterruptedException {
3343
synchronized (this) {
3444
System.out.println("Producer thread running ....");

0 commit comments

Comments
 (0)