当我尝试使用该类扩展 GlobalSettings 时,我需要每天在 playframework2.0.4 中执行一段代码。但它适用于每个请求的实例。我希望它在服务器启动并每天执行 1 次时工作。
package controllers;
import java.util.concurrent.TimeUnit;
import akka.util.Duration;
import play.Application;
import play.GlobalSettings;
import play.libs.Akka;
public class ParserJobApp extends GlobalSettings{
@Override
public void onStart(Application app) {
Akka.system().scheduler().schedule(Duration.create(0, TimeUnit.MILLISECONDS),Duration.create(6, TimeUnit.SECONDS), new Runnable() {
@Override
public void run() {
System.out.println("AAA --- "+System.currentTimeMillis());
}
});
}
}
这是我的控制器,开始上面的课程
public class Application extends Controller {
public static Result index() {
ParserJobApp pr=new ParserJobApp();
pr.onStart(null);
System.out.println("sfsdfsdf");
return ok(index.render("Your new "));
}
}