gpt4 book ai didi

java - 游戏框架中的 Cron Job

转载 作者:行者123 更新时间:2023-12-04 05:47:39 25 4
gpt4 key购买 nike

我正在尝试使用 Play Framework 创建 Web 服务,我想通过 scheduling 加入它,每一分钟都会调用getRunJob() .

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

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

应用程序.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()));
}

}

调度程序.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

最佳答案

将协议(protocol)添加到 WS.url:

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

关于java - 游戏框架中的 Cron Job,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10479556/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com