Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Servlet 3.0 async Supported disadvantages

In my application I have a homegrown framework which maps all the requests to a central ControllerServlet (nothing fancy, it has the basic functionality of almost any framework). I have to implement a Publisher-Subscriber messaging exchange feature and I decided to use Servlet 3.0's asynchronous methods.

The current ControllerServlet and AuthenticationFilter are not setted as asyncSupported. I could either implement a second CotrollerServlet for all the async processing or declare the existing ControllerServlet as asyncSupported=true (even though there are requests that do not need async processing ).

... for an application to use the asynchronous feature, the entire request processing chain must have the have this attribute set either through the annotation or in its deployment descriptor ... - source

From here I understand that I have to declare the AuthenticationFilter as asyncSupported=true (and again there are cases when the async is not needed).

Is there any downsides of declaring servlets and filters as asyncSupported=true even though they also map requests that do not need async processing? Will there be any scalability problems?

like image 913
Ionut Avatar asked Nov 14 '22 00:11

Ionut


1 Answers

The 2.3.3.3 Asynchronous processing chapter of Java Servlet 3.0 specification contains a hint:

Dispatching from a synchronous servlet to an asynchronous servlet would be illegal. However the decision of throwing an IllegalStateException is differed to the point when the application calls startAsync. This would allow a servlet to either function as a synchronous or an asynchronous servlet.

It's not stated directly, but this sentence makes me believe that such dual synchronous/asynchronous nature of one servlet isn't something unusal as far as JLS authors are concerned.

On the other hand consult your container's documentation/source code. Just because it's legal from JLS point of view doesn't mean your container isn't doing some clever optimizations that have negative impact on performance if AsyncContext isn't really used. Otherwise, if all servlets could simply work in either mode, what would be the purpose of this attribute, except documenting?

like image 73
Tomasz Nurkiewicz Avatar answered Dec 19 '22 05:12

Tomasz Nurkiewicz