BAEL-614 Added "public" to class definitions; Formatted code
This commit is contained in:
parent
955d26116c
commit
4ff894095c
|
@ -1,6 +1,5 @@
|
||||||
package com.baeldung.concurrent.blockingqueue;
|
package com.baeldung.concurrent.blockingqueue;
|
||||||
|
|
||||||
|
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
|
||||||
|
@ -10,7 +9,6 @@ public class BlockingQueueUsage {
|
||||||
int N_PRODUCERS = 4;
|
int N_PRODUCERS = 4;
|
||||||
int N_CONSUMERS = Runtime.getRuntime().availableProcessors();
|
int N_CONSUMERS = Runtime.getRuntime().availableProcessors();
|
||||||
|
|
||||||
|
|
||||||
BlockingQueue<Integer> queue = new LinkedBlockingQueue<>(BOUND);
|
BlockingQueue<Integer> queue = new LinkedBlockingQueue<>(BOUND);
|
||||||
|
|
||||||
for (int i = 0; i < N_PRODUCERS; i++) {
|
for (int i = 0; i < N_PRODUCERS; i++) {
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
package com.baeldung.concurrent.blockingqueue;
|
package com.baeldung.concurrent.blockingqueue;
|
||||||
|
|
||||||
|
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
|
|
||||||
class NumbersConsumer implements Runnable {
|
public class NumbersConsumer implements Runnable {
|
||||||
private final BlockingQueue<Integer> queue;
|
private final BlockingQueue<Integer> queue;
|
||||||
|
|
||||||
public NumbersConsumer(BlockingQueue<Integer> queue) {
|
public NumbersConsumer(BlockingQueue<Integer> queue) {
|
||||||
|
@ -16,7 +15,6 @@ class NumbersConsumer implements Runnable {
|
||||||
Integer number = queue.take();
|
Integer number = queue.take();
|
||||||
String result = number.toString();
|
String result = number.toString();
|
||||||
System.out.println(Thread.currentThread().getName() + " result: " + result);
|
System.out.println(Thread.currentThread().getName() + " result: " + result);
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
|
|
|
@ -1,20 +1,16 @@
|
||||||
package com.baeldung.concurrent.blockingqueue;
|
package com.baeldung.concurrent.blockingqueue;
|
||||||
|
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
|
|
||||||
|
public class NumbersProducer implements Runnable {
|
||||||
class NumbersProducer implements Runnable {
|
|
||||||
private final Random random = new Random();
|
private final Random random = new Random();
|
||||||
private final BlockingQueue<Integer> numbersQueue;
|
private final BlockingQueue<Integer> numbersQueue;
|
||||||
|
|
||||||
|
|
||||||
public NumbersProducer(BlockingQueue<Integer> numbersQueue) {
|
public NumbersProducer(BlockingQueue<Integer> numbersQueue) {
|
||||||
this.numbersQueue = numbersQueue;
|
this.numbersQueue = numbersQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
generateNumbers();
|
generateNumbers();
|
||||||
|
|
Loading…
Reference in New Issue