TimerTask vs ScheduledThreadPool vs HashedThreadWheel

时间:2013-07-16 17:07:35

标签: java scala playframework-2.0

这是TimerTask vs ScheduledThreadPoolExecutor vs netty的HashedWheelTimer问题。

我正在查看播放框架文档。 timeout中有一个名为play.api.libs.concurrent.Promise的方法。基本上它安排了要执行的任务。以下是实施:

private val timer = new java.util.Timer()

def timeout[A](message: => A, duration: Long, unit: TimeUnit = TimeUnit.MILLISECONDS)(implicit ec: ExecutionContext): Future[A] = {
val p = Promise[A]()
timer.schedule( new java.util.TimerTask{
  def run(){
    p.completeWith(Future(message)(ec))
  }
},unit.toMillis(duration) )
p.future

}

为什么TimerTask是更好的实施时,他们会在SCTE使用HashedWheelTimer。为什么即使Akka将其用于scheduler时,netty的{{1}}也是如此?如何优于另一个。

0 个答案:

没有答案
相关问题