Skip to content

Instantly share code, notes, and snippets.

@duese
Created March 24, 2016 00:19
Show Gist options
  • Save duese/ba6089bd2f8c87878c4d to your computer and use it in GitHub Desktop.
Save duese/ba6089bd2f8c87878c4d to your computer and use it in GitHub Desktop.
// http://stackoverflow.com/questions/510462/is-system-nanotime-completely-useless
import scala.collection.mutable
val numThreads = 10
val numValuesPerThread = 10
var threadResult = mutable.Map[Int, Seq[Long]]()
val threadList = for (currentThreadIndex <- 0 to numThreads) yield {
new Thread(new Runnable {
override def run(): Unit = {
threadResult(currentThreadIndex) =
(0 to numValuesPerThread).map { case _ => System.nanoTime }
}
}, s"thread-$currentThreadIndex")
}
threadList foreach { thread => thread.start() }
println(s"All threads started. (result size = ${threadResult.size})")
threadList foreach { thread => thread.join() }
println(s"All threads joined. (result size = ${threadResult.size})")
for (currentThreadIndex <- 0 to numThreads;
currentValueIndex <- 0 to numValuesPerThread) {
val list: Seq[Long] = threadResult(currentThreadIndex)
}
var l0 = List(1,2,3,4,8)
@duese
Copy link
Author

duese commented Mar 25, 2016

@duese
Copy link
Author

duese commented Mar 25, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment