我正在尝试使用Akka和调度程序Play! java中的框架2.1.1 我已经在Scala中使用它,使用Play 2.1.0,但导入并不是全部都有效。
我目前的进口商品:
import play.Application;
import play.GlobalSettings;
import play.Logger;
import play.libs.*;
import utils.MongoUtil;
import play.libs.Akka;
import akka.actor.ActorRef;
import akka.actor.Props;
import java.util.*;
import java.util.concurrent.TimeUnit;
import jobs.*;
import models.User;
import scala.concurrent.duration.Duration;
import scala.concurrent.duration.FiniteDuration;
import com.mongodb.*;
我的代码:
ActorRef cron = Akka.system().actorOf(new Props(Cron.class));
Akka.system().scheduler().schedule(
Duration.create(0, TimeUnit.SECONDS),
Duration.create(24, TimeUnit.HOURS),
cron,
"tick"
);
堆栈跟踪:
error: no suitable method found for schedule(FiniteDuration,FiniteDuration,ActorRef,String)
[error] Akka.system().scheduler().schedule(
[error] ^
[error] method Scheduler.schedule(FiniteDuration,FiniteDuration,Runnable,ExecutionContext) is not applicable
[error] (actual argument ActorRef cannot be converted to Runnable by method invocation conversion)
[error] method Scheduler.schedule(FiniteDuration,FiniteDuration,Function0<BoxedUnit>,ExecutionContext) is not applicable
[error] (actual argument ActorRef cannot be converted to Function0<BoxedUnit> by method invocation conversion)
[error] method Scheduler.schedule(FiniteDuration,FiniteDuration,ActorRef,Object,ExecutionContext) is not applicable
[error] (actual and formal argument lists differ in length)
我尝试了很多我在网上找到的东西,但似乎没什么用。
提前致谢!
编辑:当你没有在最后一个版本的API doc上自动重新编写时,我真的不喜欢...答案 0 :(得分:1)
错误非常明显:
[error] method Scheduler.schedule(FiniteDuration,FiniteDuration,Runnable,ExecutionContext) is not applicable
[error] (actual argument ActorRef cannot be converted to Runnable by method invocation conversion)
因此,ActorRef
不是Runnable
。
你必须以这种方式调用时间表(好吧,不完全是这样,为你的程序修改它):
system.scheduler().schedule(Duration.create(50, TimeUnit.MILLISECONDS),
new Runnable() {
...
}
}, system.dispatcher());