How does a single servlet handle multiple requests from client side

前端 未结 3 1907
梦如初夏
梦如初夏 2021-01-30 17:58

How does a single servlet handle multiple client requests coming in the form of user requests ? Based on the singleton design pattern I know we get a single instance of servlet

3条回答
  •  无人及你
    2021-01-30 18:25

    You don't create multiple instances of servlet. The servlet engine utilizes a separate thread from the thread pool for each request (up to some max number of Threads allocated).

    The performance is relative to the number of threads, not the number of instances of the servlet.

    For example, if there are 1000 requests, and the maximum threads that can be generated by servlet is 100, then there will be performance degradation.

    In order to avoid this problem, we can use load balancer by putting multiple servers behind a load balancer. The load balancer should be configured to "route" the requests to any one of the servers based upon different parameters/settings (round robin distribution, load distribution etc.). The more load you need, the more servers you should add. However, this does send all traffic through the load balancer so it is important that this be redundant and failover safe.

提交回复
热议问题