Search code examples
javajavascriptrestletlong-polling

Implementing long-polling in server


i'm trying to develop a long-polling on my javascript client and in my server that management the http requests. In server i have a restlet listening the request and processing them, in the client i have a javascript api that make http calls with xmlhttprequest object.

Now i have in js a setTimeOut with a delay of 3 seconds that makes polling to the server, in most request i receive nothing, i want to implement a long-polling. My question is if i have to implement in my server the logic of long-polling, my reslet uses jetty, and i would to implement something like 'Thread.sleep' until i have any to send to client? or i have natively methods in java or restlet that allow me to do without long implementation.

I appreciate your answers!


Solution

  • Actually, i have implemented the long polling using the java concurrency: wait() & notify() system for java objects.