From c686fb1168f662a7eb4bec4a64858fa5995de096 Mon Sep 17 00:00:00 2001 From: JojiKoike Date: Fri, 26 Jun 2020 19:13:23 +0900 Subject: [PATCH] =?UTF-8?q?ExecutorService=E3=82=92=E5=88=A9=E7=94=A8?= =?UTF-8?q?=E3=81=97=E3=81=A6OutOfMemoryError=E3=82=92=E9=98=B2=E6=AD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/scala/TenThousandNamePrinter.scala | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) 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 +}