开发者

Java Servlets threading model

开发者 https://www.devze.com 2022-12-17 08:54 出处:网络
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 mu

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 开发者_如何学JAVAserialization process happens...

Can anybody explain it?


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.

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.


Historically you had two models, depending on your Servlet. If the Servlet implemented SingleThreadModel, then the requests where queued. Otherwise, and this is the only model now, a Servlet must be able to serve multiple requests at the same time. So there is no queueing in that model, unless the container has some rate-limiting functionnality.


yes,there is a interface single thread model .it is a marker interface. it makes this object of servlet synchronized i.e at a time only one thread serve the object.but it create the problems like response delay.for solution they create pool of objects but again pool also has limited size.so it is better to use synchronized block

0

精彩评论

暂无评论...
验证码 换一张
取 消