Browse Source

#1152 Fix for Scruffy to use ThreadLocalRandom

Stephen Samuel 10 years ago
parent
commit
c796763461

+ 2 - 2
frameworks/Scala/scruffy/src/main/scala/scruffy/examples/Test2Endpoint.scala

@@ -2,6 +2,7 @@ package scruffy.examples
 
 import com.mongodb.casbah.Imports._
 import com.sksamuel.scruffy.EndpointProvider
+import java.util.concurrent.ThreadLocalRandom
 
 /** @author Stephen Samuel */
 class Test2Endpoint() extends EndpointProvider {
@@ -9,7 +10,6 @@ class Test2Endpoint() extends EndpointProvider {
   val connection = MongoConnection(hostname, 27017)
   val collection = connection.getDB("hello_world").getCollection("world")
 
-  val random = new scala.util.Random(System.currentTimeMillis)
   val fields = DBObject("_id" -> true, "randomNumber" -> true)
 
   //uncomment to populate
@@ -18,7 +18,7 @@ class Test2Endpoint() extends EndpointProvider {
 
   get("db").json {
     req =>
-      val id = random.nextInt(10000)
+      val id = ThreadLocalRandom.current.nextInt(10000)
       val dbo = collection.findOne(DBObject("_id" -> id), fields)
       val randomNumber = Math.round(dbo.get("randomNumber").toString.toFloat)
       Output(id, randomNumber)