BAEL-614 thread local random
This commit is contained in:
parent
2c0494dd03
commit
0639b2cd6f
|
@ -1,12 +1,11 @@
|
|||
package com.baeldung.concurrent.blockingqueue;
|
||||
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
|
||||
class NumbersProducer implements Runnable {
|
||||
private final Random random = new Random();
|
||||
private final BlockingQueue<Integer> numbersQueue;
|
||||
private final int poisonPill;
|
||||
private final int poisonPillPerProducer;
|
||||
|
@ -29,7 +28,7 @@ class NumbersProducer implements Runnable {
|
|||
|
||||
private void generateNumbers() throws InterruptedException {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
numbersQueue.put(random.nextInt(100));
|
||||
numbersQueue.put(ThreadLocalRandom.current().nextInt(100));
|
||||
}
|
||||
for (int j = 0; j < poisonPillPerProducer; j++) {
|
||||
numbersQueue.put(poisonPill);
|
||||
|
|
Loading…
Reference in New Issue