i have a jersey service which contains a timer task, which polls for a particular value. i want to return a response only when i get a particular value from the polling. is there any way i can accomplish that?
My code is:
@Path("/poll")
public class PollService{
String response = null;
@GET
@Produces(javax.ws.rs.core.MediaType.TEXT_PLAIN)
public String pollResponse(@Context HttpServletRequest request){
MyTimer poller = new MyTimer();
final Timer timer = new Timer();
timer.scheduleAtFixedRate(poller, 0, 5000);
return response;
}
private class MyTimer extends TimerTask{
@Override
public void run(){
//Poll
//Change value of response upon condition
}
}
I don't want the service to return any value until the value of "response" variable is set to say "SUCCESS". what may I do to accomplish that?