diff --git a/src/main/scala/TenThousandNamePrinter.scala b/src/main/scala/TenThousandNamePrinter.scala index c31ee74..e57af79 100644 --- a/src/main/scala/TenThousandNamePrinter.scala +++ b/src/main/scala/TenThousandNamePrinter.scala @@ -1,10 +1,15 @@ +import java.util.concurrent.Executors + object TenThousandNamePrinter extends App { + val es = Executors.newFixedThreadPool(10) + for (i <- 1 to 10000) { - new Thread(() => { - Thread.sleep(1000) - println(Thread.currentThread().getName) - }).start() + es.submit(new Runnable { + override def run(): Unit = { + Thread.sleep(1000) + println(Thread.currentThread().getName) + } + }) } - -} \ No newline at end of file +}