Skip to content

Commit afcb26a

Browse files
authored
Merge pull request eugenp#4992 from Doha2012/master
fix blocking queue
2 parents cb86a05 + 08d4356 commit afcb26a

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎core-java-concurrency/src/main/java/com/baeldung/concurrent/blockingqueue/BlockingQueueUsage.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@ public static void main(String[] args) {
1010
int N_CONSUMERS = Runtime.getRuntime().availableProcessors();
1111
int poisonPill = Integer.MAX_VALUE;
1212
int poisonPillPerProducer = N_CONSUMERS / N_PRODUCERS;
13-
13+
int mod = N_CONSUMERS % N_PRODUCERS;
1414
BlockingQueue<Integer> queue = new LinkedBlockingQueue<>(BOUND);
1515

16-
for (int i = 0; i < N_PRODUCERS; i++) {
16+
for (int i = 1; i < N_PRODUCERS; i++) {
1717
new Thread(new NumbersProducer(queue, poisonPill, poisonPillPerProducer)).start();
1818
}
1919

2020
for (int j = 0; j < N_CONSUMERS; j++) {
2121
new Thread(new NumbersConsumer(queue, poisonPill)).start();
2222
}
23+
24+
new Thread(new NumbersProducer(queue, poisonPill, poisonPillPerProducer+mod)).start();
25+
2326
}
2427
}

0 commit comments

Comments
 (0)