Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asynchronous Servlets vs. synchronous Servlets

Since Servlet 3.0 asynchronous processing is supported. Would it be better, to use always asynchronous processing? Or in what cases is synchronous processing better?

like image 282
deamon Avatar asked Jan 29 '10 15:01

deamon


People also ask

What is asynchronous servlet?

In short, an asynchronous servlet enables an application to process incoming requests in an asynchronous fashion: A given HTTP worker thread handles an incoming request and then passes the request to another background thread which in turn will be responsible for processing the request and send the response back to the ...

What is AsyncContext in Java?

public interface AsyncContext. Class representing the execution context for an asynchronous operation that was initiated on a ServletRequest. An AsyncContext is created and initialized by a call to ServletRequest.

Which of the following method is used to get instance of AsyncContext?

To obtain an instance of AsyncContext , call the startAsync() method on the request object of your service method; for example: public void doGet(HttpServletRequest req, HttpServletResponse resp) { ... AsyncContext acontext = req.

What are the advantages of servlets?

The advantages of Servlet are as follows: Better performance: because it creates a thread for each request, not process. Portability: because it uses Java language. Robust: JVM manages Servlets, so we don't need to worry about the memory leak, garbage collection, etc.


1 Answers

The big thing you get with asynchronous servlets is HTTP push, where the server can fire information back to the client when it chooses to, rather than when the client asks for it. Pre-asynch servlets, this would require long-running HTTP connections which each tied up a server thread, which is very inefficient. This new model decouples the server-side processing from the connection handling.

like image 64
skaffman Avatar answered Sep 22 '22 15:09

skaffman