fix blocking queue
This commit is contained in:
parent
cee1fafe95
commit
08d4356d5b
|
@ -10,15 +10,18 @@ public class BlockingQueueUsage {
|
||||||
int N_CONSUMERS = Runtime.getRuntime().availableProcessors();
|
int N_CONSUMERS = Runtime.getRuntime().availableProcessors();
|
||||||
int poisonPill = Integer.MAX_VALUE;
|
int poisonPill = Integer.MAX_VALUE;
|
||||||
int poisonPillPerProducer = N_CONSUMERS / N_PRODUCERS;
|
int poisonPillPerProducer = N_CONSUMERS / N_PRODUCERS;
|
||||||
|
int mod = N_CONSUMERS % N_PRODUCERS;
|
||||||
BlockingQueue<Integer> queue = new LinkedBlockingQueue<>(BOUND);
|
BlockingQueue<Integer> queue = new LinkedBlockingQueue<>(BOUND);
|
||||||
|
|
||||||
for (int i = 0; i < N_PRODUCERS; i++) {
|
for (int i = 1; i < N_PRODUCERS; i++) {
|
||||||
new Thread(new NumbersProducer(queue, poisonPill, poisonPillPerProducer)).start();
|
new Thread(new NumbersProducer(queue, poisonPill, poisonPillPerProducer)).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int j = 0; j < N_CONSUMERS; j++) {
|
for (int j = 0; j < N_CONSUMERS; j++) {
|
||||||
new Thread(new NumbersConsumer(queue, poisonPill)).start();
|
new Thread(new NumbersConsumer(queue, poisonPill)).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new Thread(new NumbersProducer(queue, poisonPill, poisonPillPerProducer+mod)).start();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue