1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
object Test { def main(args: Array[String]): Unit = { class Singleton { val field = () println("Initializing singleton.") } lazy val Singleton = new Singleton var i = 0 while (i < 4) { new Thread(new Runnable { def run = Singleton.field }).start i += 1 } } }