Java Magazine, Jan/Feb 2016
Long Polling with Asynchronous Servlets The reliable workhorse of client server communications is the easy to use fallback when other methods dont work HENRY NAFTULIN ORACLE COM JAVAMAGAZINE JANUARY FEBRUARY 2016 41 web apps Not too long ago a large gap existed between desktop applications and web applications If you go back 10 years desktop applications were noticeably more responsive had far better user interfaces and overall presented a much better user experience A major reason why web based applications were far behind in user experience was because they were not as responsive to server state changes as their desktop counterparts and users had to update a whole page to get new data on the screen Back then in order to compete with desktop apps companies that produced web applications used a variety of different tactics They used applets Adobe Flash applications Comet or similar frameworks that were popular at the time while others used raw Ajax calls Even with all these technologies web apps couldnt compete with desktop software for usability Nowadays web applications are expected to be interactive have a stellar looking UI and do almost as much as their desktop counterparts With rich front end UI frameworks such as Bootstrap and processing frameworks such as jQuery and Angular JS it is much easier to build applications that are easy on the eyes and can quickly respond to user input notifying a server about changes made in the UI But what about propagating the changes from the server to the web clients After all given todays cutting edge technology we are used to and expect almost instantaneous UI feedback to anything that is happening to the information on the server In this article I explore one such solution long polling and briefly take a look at its alternatives Long Polling and Its Alternatives For a long time web applications were developed in an n tiered usually three tiered architecture in which the client initiated requests for data from the server There was no way for the server to push data to the client without the client requesting an update Yet in many applications a change on the server needs to be propagated to the clients in a timely manner To work around this limitation a technique known as long polling can be used Long polling is a technique used to push updates to a web client After a client requests new information the server holds the request until new data becomes available Once the server receives new data it completes the clients response by sending the data to the client At this point the server can either keep the connection open while sending further updates to the client as they happen or close the connection right away In the latter case once the client receives the response from the server and the connection is closed the client immediately sends another request for an update and the operation is repeated
You must have JavaScript enabled to view digital editions.