From 89ea0113b27b3bbb2629eedda2638796699ea257 Mon Sep 17 00:00:00 2001 From: Henry Liu Date: Mon, 17 Sep 2012 22:30:31 -0400 Subject: [PATCH] ensure proper JVM shutdown --- core/src/main/scala/execution.scala | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/core/src/main/scala/execution.scala b/core/src/main/scala/execution.scala index 151b0ad4..15922dad 100644 --- a/core/src/main/scala/execution.scala +++ b/core/src/main/scala/execution.scala @@ -29,9 +29,18 @@ class Http extends FixedThreadPoolExecutor { self => } } +// produce thread(daemon=true), so it doesn't block JVM shutdown +class DaemonThreadFactory extends juc.ThreadFactory { + def newThread(r: Runnable):Thread ={ + val thread = new Thread + thread.setDaemon(true) // this ensure the created threads don't prevent jVM from porpoer shutdown + thread + } +} + trait FixedThreadPoolExecutor extends Executor { def threadPoolSize: Int - lazy val promiseExecutor = juc.Executors.newFixedThreadPool(threadPoolSize) + lazy val promiseExecutor = juc.Executors.newFixedThreadPool(threadPoolSize,new DaemonThreadFactory) } trait Executor { self =>