📄 e1041. preventing concurrent requests to a servlet.txt
字号:
By default, a servlet container will use a servlet instance to concurrently process multiple requests. Although, this behavior burdens the servlet developer to properly synchronize shared state, this ability to handle multiple requests allows for a more scalable architecture. However, if it is necessary to disable this ability, the servlet should implement the SingleThreadModel interface:
// This servlet can only handle a single request at a time.
public class MyServlet extends HttpServlet implements SingleThreadModel {
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
// Handle GET request...
}
}
However, forcing the servlet container to route requests one at a time through a servlet does not prevent the container from creating multiple instances of the servlet. Hence, the servlet developer must still properly synchronize shared state. Effectively, the main benefit of implementing the SingleThreadModel is not having to synchronize the servlet's instance variables.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -