我想使用一個簡單的@Schedule,所以我可以稍後使用它... 我的web應用程序只包含一個index.html 如果我去到./api/test/我會去我的由EJB管理的控制器。 在此控制器中,我使用@Schedule annation調用方法。但我只是不明白如何得到這個工作... runscript方法添加一個計數器字段,所以我的index.html文件顯示數字:1.但我的號碼從未走得更高,我什至不看任何sysouts ..所以我想我的@schedule不會被觸發?@Schedule將無法工作EJB - Java EE - Web應用程序
這是我的兩個只用代碼文件:
@Path("/test")
public class controller {
NewClass test;
public controller() {
test = new NewClass();
}
@GET
public Response getObservation() {
try {
//Object to JSON in String
test.runningScript();
System.out.println("getObservation");
System.out.println(test.getText());
String jsonInString = test.getText();
return Response.status(200).entity(jsonInString).build();
} catch (Exception ex) {
System.out.println("error");
ex.printStackTrace();
return null;
}
}
}
類調度
public class NewClass {
private int counter = 0;
private String text = "test";
public NewClass() {
}
public String getText(){
return text;
}
private void setText(String text){
this.text = text;
}
@Schedule(hour="*", minute="*", second="*/5")
public void runningScript() {
counter++;
System.out.println("*******test runningscript*****");
System.out.println(counter);
text = "number : " + counter;
}
}
有人的想法,我怎麼能得到這個工作? 我搜索了幾個小時:ss
您通常不應該使用'@ Schedule'調用註解的方法。你想做什麼,發生了什麼? –
稍後我想每隔x秒閱讀一次腳本,由@schedule安排... – Tom
但我現在正在測試使用@schedule。他甚至不會每5秒鐘給我的系統管理員如果我運行該方法?如果我最好不要調用Schedule的註釋方法,那麼我該如何啓動它們? – Tom