Java Servlets线程模型 [英] Java Servlets threading model

查看:57
本文介绍了Java Servlets线程模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人可以向我解释Java Servlet的线程模型? 据我了解,该servlet容器中只能存在一个servlet实例,并且如果多个线程正巧在等待该servlet,则会以某种方式对请求进行序列化. 我不知道序列化过程是如何发生的...

I was wondering if anybody could explains me the threading model of Java Servlets? As I understood about that, there is only one instance of a servlet can be existed in the servlet container and if muliple threads happens to be waiting for that servlet, there requests are serialized in some manner. I don't know how that serialization process happens...

有人可以解释吗?

推荐答案

如果请求是由servlet串行处理的,则Web应用程序将非常慢.小服务程序实际上必须是线程安全的,因为小服务程序的单个实例可以负责同时处理多个请求.

If requests were handled serially by servlets, then web applications would be very slow. It's actually the case that servlets need to be thread-safe, because a single instance of a servlet can be responsible for handling multiple requests simultaneously.

通常,Web应用程序容器将维护一个线程池以处理请求,传入请求将按需分配给线程.

Usually a web application container will maintain a thread pool for handling requests, with incoming requests being assigned to threads on an on-demand basis.

这篇关于Java Servlets线程模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆