Tom
Tom

Reputation: 85

@Schedule won't work EJB - Java EE - Web application

I am trying to use a simple @Schedule, so I can use it later on ... My web app only contains an index.html If I go to ./api/test/ I will go to my controller managed by EJB. In this controller I call a method with a @Schedule annation. But I just don't understand how to get this to work ... The runningscript method add the counter field by one so my index.html file display number: 1. But my number never goed higher, I don't even see any sysouts .. So I suppose my @schedule don't get triggered ?

This are my two only used code files:

@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;
    }
}
}

class with scheduling

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;
}
}

Someone an Idea how I could get this to work ? I searched for hours :ss

Upvotes: 0

Views: 695

Answers (1)

Philippe Marschall
Philippe Marschall

Reputation: 4604

NewClass is not an EJB. @Schedule only works on EJBs.

Upvotes: 4

Related Questions