views:

52

answers:

1

I am working on an application which uses tomcat as a web server and java swing app. as only client to communicate to the web server via webservices.

I am stuck in a situation where i need the server to somehow notify the client of some kind of updated event, that occurred on the server side. Something like reverse ajax or similar.

Any ideas...

Abdul Khaliq

A: 

The most common approach will be your client to poll the server. This means to issue periodically requests to the server to ask for new events. This will introduce a delay between the appearance of an event and its notification to the client.

Another approach is to issue an HTTP request from the client and leave it open, until an event appears. This way the notifications arrive immediately after an event. When an event is reported, you issue another request. This approach has the disadvantage that it greatly restricts the number of clients that a server can server at any time. The default value of threads for Tomcat is 150. For every http request you need one thread, so you can't have more than 150 open requests.

kgiannakakis
Notice that new tomcat has comment support, which should handle long polls much more efficiently, without wasting threads.
David Rabinowitz
Which version of Tomcat are you referring to? Where can I find more info?
kgiannakakis
One important thing to mention is thread management: the polling thread (NOT the EDT) will have to feedback to the GUI through SwingUtilities.invokeLater() or invokeAndWait().
jfpoilpret