Cron Job在游戏框架中

时间:2012-05-07 09:19:21

标签: java asynchronous playframework cron playframework-1.x

我正在尝试使用Play Framework创建网络服务,我希望将其加入scheduling,每分钟都会调用getRunJob()

直接拨打http://localhost:9000/run时有效,但当我尝试使用Scheduler从我的WS.WSRequest resp = WS.url("localhost:9000/run");班级拨打电话时,它会变为错误java.lang.IllegalArgumentException: Illegal URL: localhost://null

我的代码有什么问题吗?请指教,谢谢...

Application.java

public class Application extends Controller {

    public static void index() {
        render();
    }

    public static void getRunJob() {
        SimpleDateFormat format = new SimpleDateFormat("HH:MM");
        renderText("Running... " + format.format(new Date()));
    }

}

Scheduler.java

@On("1 * * * * ?")
public class Scheduler extends Job {

    @Override
    public void doJob() {
        System.out.println("Test");
        WS.WSRequest resp = WS.url("localhost:9000/run");
        System.out.println(resp.get().getString());
    }
}

路由

GET     /                                       Application.index
GET     /run                                    Application.getRunJob

1 个答案:

答案 0 :(得分:3)

将协议添加到WS.url:

WS.WSRequest resp = WS.url("http://localhost:9000/run");