From: Jérôme Benoit Date: Tue, 6 Mar 2018 22:38:54 +0000 (+0100) Subject: TD1: Use a thread optimized random number generator. X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=b0f9b27c32d4599150eec0ce102695b328d87e7c;p=TD_SR.git TD1: Use a thread optimized random number generator. Signed-off-by: Jérôme Benoit --- diff --git a/TD1/exo2/ThreadJob.java b/TD1/exo2/ThreadJob.java index dae83ba..32a7365 100644 --- a/TD1/exo2/ThreadJob.java +++ b/TD1/exo2/ThreadJob.java @@ -1,4 +1,4 @@ -import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; public class ThreadJob implements Runnable { @@ -12,8 +12,7 @@ public class ThreadJob implements Runnable { public void run() { for (int j = 0; j < 10; j++) { - Random rand = new Random(); - int sleep_time = rand.nextInt(201); + int sleep_time = ThreadLocalRandom.current().nextInt(201); try { Thread.sleep(sleep_time); }