I want to know the meaning of the asynchronous servlet.

Asked 2 years ago, Updated 2 years ago, 78 views

Hello, I heard that the function of asynchronously processing HTTP requests has been added to Servlet 3. I think there's no reason to add the concept of asynchronous servlet to it, as the servlet itself is already being operated as a thread inside the Tomket server anyway. Am I mistaken? Thank you.

jsp

2022-09-22 21:15

1 Answers

The method used in servlet 2 is called thread per connection. When a client connects, it assigns one thread to the client and the thread processes the user's request. This method hides the use of multi-threads from developers, and even if you create a servlet page as if you are developing it as a single thread, containers such as Tomket can distribute user requests to various threads.

These functions were sufficient, but as the web developed, functions such as server push became necessary. This functionality requires maintaining connectivity between the user and the server, which leads to the problem of continuing to occupy the thread, which is not actually working, but still occupying the resources.

jvm requires approximately 1 MB (stack 512k + heap@) of resources per thread. These days, server resources have become quite abundant, but when Servlet 3 came out, the typical was memory was less than 4G. It is difficult to increase concurrent users even with simple calculations. This includes memory problems as well as context switching costs between threads.

The method used in servlet 3 is called thread per request. thread is not assigned per client connection, but thread provided within a certain size of thread pool is reused per request. Therefore, the number of threads does not increase depending on the number of users connection.

The advantage of this approach is that it's great in terms of resource utilization, but it complicates the code and requires the right utilization for the right use.

p.s: Traditional methods work as multi-threads, but each thread is blocked, which creates a problem. Multi-threaded!= Asynchronous.


2022-09-22 21:15

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.