Trying to implement simple Ajax polling without Websockets or anything else.
Now, my ajax looks like this:
// start simple long term polling
(function poll(){
$.ajax({
url: "/app/api/ltp/receive",
success: function(data) {
// do some stuff
},
dataType: "json",
complete: poll,
timeout: 30000 // again and again
});
})();
The problem is on server side:
I have to check message queue for new messages and block some time before checking again. When there is a message, I can send json back to the client, holding the connection with an extra long timeout.
But as I know, in CDI I should never use Thread.sleep(ms) to block, right? What can I do instead?