Skip to content

Commit

Permalink
Merge pull request #25 from tohenryliu/shutdown
Browse files Browse the repository at this point in the history
ensure proper JVM shutdown
  • Loading branch information
Nathan Hamblen committed Oct 7, 2012
2 parents b04e6fa + 89ea011 commit 90bceaa
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion core/src/main/scala/execution.scala
Expand Up @@ -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 =>
Expand Down

0 comments on commit 90bceaa

Please sign in to comment.