Skip to content

Commit b531a8a

Browse files
committed
CountDownLatch_7.App#App
Clean up auto-generated catch blocks re-activated the 0.1sec pause in consumer() (for the sake of not flooding the output terminal) Commented out {t1,t2}.join() ... instead, forced the app (main thread) to quite after 30secs
1 parent 8ed7488 commit b531a8a

File tree

1 file changed

+10
-13
lines changed
  • JavaMultiThreadingCodes/src/ProducerConsumer_7

1 file changed

+10
-13
lines changed

JavaMultiThreadingCodes/src/ProducerConsumer_7/App.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,30 @@ public class App {
3232
private static BlockingQueue<Integer> queue = new ArrayBlockingQueue<>(10);
3333

3434
public static void main(String[] args) throws InterruptedException {
35-
/**
36-
*
37-
*/
35+
3836
Thread t1 = new Thread(new Runnable() {
3937
public void run() {
4038
try {
4139
producer();
42-
} catch (InterruptedException e) {
43-
e.printStackTrace();
44-
}
40+
} catch (InterruptedException ignored) {}
4541
}
4642
});
4743

4844
Thread t2 = new Thread(new Runnable() {
4945
public void run() {
5046
try {
5147
consumer();
52-
} catch (InterruptedException e) {
53-
// TODO Auto-generated catch block
54-
e.printStackTrace();
55-
}
48+
} catch (InterruptedException ignored) {}
5649
}
5750
});
5851
t1.start();
5952
t2.start();
60-
t1.join();
61-
t2.join();
53+
// t1.join();
54+
// t2.join();
55+
56+
// Pause for 30 seconds and force quitting the app (because we're looping infinitely)
57+
Thread.sleep(30000);
58+
System.exit(0);
6259
}
6360

6461
private static void producer() throws InterruptedException {
@@ -71,7 +68,7 @@ private static void producer() throws InterruptedException {
7168
private static void consumer() throws InterruptedException {
7269
Random random = new Random();
7370
while (true) {
74-
//Thread.sleep(100);
71+
Thread.sleep(100);
7572
if (random.nextInt(10) == 0) {
7673
Integer value = queue.take();//if queue is empty waits
7774
System.out.println("Taken value: " + value + "; Queue size is: " + queue.size());

0 commit comments

Comments
 (0)