1
몇 밀리 초마다 액터를 "호출"하고 싶습니다. 그러나 스케줄러가 정확하지 않다는 것을 알았습니다.akka 스케줄러의 정확도를 높일 수 있습니까?
여기, 인쇄 결과가 akka은 0,10,30에 덩어리에게 시간을 보이는 등 한편
이 Thread.sleep
는 사실 매우 정확하다는 것을 보여줍니다 코드
def work3(): Unit ={
val rate = 12
var n = 0
val a = system.actorOf(Props(new Actor{
var t1 = System.currentTimeMillis()
def receive= {
case _ =>
//context.system.scheduler.scheduleOnce(rate milliseconds,self, 1) // if I use sceduleonce it becomes even more inaccurate.
val t2 = System.currentTimeMillis()
println(t2-t1) //print 10 or 30
n += 1
t1 = t2
}
}))
system.scheduler.schedule(0 seconds,rate milliseconds,a,1)
//a ! "start"
Thread.sleep(1000*100)
println(n)
}
입니다 1 초만 자면
def work2(): Unit ={
while (true){
val t1 = System.currentTimeMillis()
Thread.sleep(1)
val t2 = System.currentTimeMillis()
println(t2-t1) // always print 1
}
}
스케줄러의 정확성을 향상시킬 수있는 방법이 있습니까?
합리적인 낮은'틱 duration'에 무엇을 바인딩을 참조하십시오? –