Sunday, April 17, 2016

Asynchronous Java Servlets


Imagine you are creating a web application for lots of clients.
and you have to do heavy processing for each client request.
the servlet thread is blocked till you process each client request.

The solution is to start separate thread for each request.
This feature is available through the asynchronous servlets of Servlet 3.0.

Quick tutorial:
https://docs.oracle.com/javaee/7/tutorial/servlets012.htm

--
p.s. you might need to declare this line of code before starting the asynchronous processing:

request.setAttribute("org.apache.catalina.ASYNC_SUPPORTED", true);

No comments: