BAEL-614 Changed to use ThreadLocalRandom instead of Random

This commit is contained in:
Pedja 2017-01-27 12:24:31 +01:00
parent 9308d7d54b
commit fb61d1b187
1 changed files with 3 additions and 3 deletions

View File

@ -1,10 +1,10 @@
package com.baeldung.concurrent.blockingqueue;
import java.util.Random;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ThreadLocalRandom;
public class NumbersProducer implements Runnable {
private final Random random = new Random();
private final BlockingQueue<Integer> numbersQueue;
public NumbersProducer(BlockingQueue<Integer> numbersQueue) {
@ -21,7 +21,7 @@ public 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));
}
}
}