I am trying to use a lengthy poll with JAX-RS (Jersey performance) and it does not work as I expect. Maybe I don’t understand something. I would be grateful for any advice.
Please note that using a reverse connection (something like Atmosphere, Comet, etc.) is not an option for security. Not that I am developing with Tomcat 7 right now.
The following method is called from a jQuery Ajax call (using $.ajax).
@Path("/poll")
@GET
public void poll(@Suspended final AsyncResponse asyncResponse)
throws InterruptedException {
new Thread(new Runnable() {
@Override
public void run() {
this.asyncResponse = asyncResponse;
latch.await(getTimeout(), TimeUnit.SECONDS);
}
}).start();
}
Another method is called from my application (after a JMS call):
@POST
@Path("/printed")
public Response printCallback() {
asyncResponse.resume("UPDATE");
latch.countDown();
return Response.ok().build();
}
If I remove the Thread creation in the method poll. Then it works, but the problem is that the thread is busy. If I use Thread creation, the method returns directly, and the browser does not detect the end of a long poll.
What am I doing wrong?