简体   繁体   English

Java Servlet大量的请求和线程

[英]Java Servlets Large number of Requests and Threads

在我的一次采访中,有人问我servlet是如何工作的,我告诉他们每个请求,servlet容器创建了一个线程,他再次在该线程上询问,然后我们是否访问了诸如facebook之类的受欢迎站点,该站点获得了大量请求,是否分配了一个线程到每个请求,那么这将不是一个好的方法,它们如何处理这么多请求。我想到了线程池,但我不知道这是否是方法。请解释一下在servlet中处理这么多请求的方法容器。

Two approaches here that complete each other: 这两种相互补充的方法:

  1. yes, limit the number of threads to a fixed number and pre-create them into a pool - thus preventing the costly process of re-creating them every time. 是的,将线程数限制为固定数量,然后将它们预先创建到池中-这样就避免了每次重新创建线程的昂贵过程。 I think Apache's HTTP server works this way. 我认为Apache的HTTP服务器以这种方式工作。

    1. You can always throw more machines at the problem. 您总是可以在问题上投入更多的计算机。 Large sites always use clusters of web-servers, thus balancing the load. 大型站点始终使用Web服务器群集,从而平衡了负载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM