SingleThreadModel (Java EE 5)

Java EE API


javax.servlet Interface SingleThreadModel


Deprecated. As of Java Servlet API 2.4, with no direct replacement.


确保 servlet 一次只处理一个请求。此接口没有方法。

如果某个 servlet 实现了此接口,则会保证 该 servlet 的 service 方法中不会有两个线程同时执行。servlet 容器通过同步对 servlet 的单个实例的访问,或者通过维护 servlet 实例池并将每个新请求分发到空闲 servlet 实现此保证。

注意,SingleThreadModel 并没有解决所有线程安全问题。例如,多个线程上的多个请求仍然可以同时访问会话属性和静态变量,即使在使用 SingleThreadModel servlet 时也是如此。建议开发人员采用实现此接口以外的其他方法解决这些问题,比如避免使用实例变量,或同步访问这些资源的代码块。此接口从 Servlet API 版本 2.4 起已经过时。

英文文档:

public interface SingleThreadModel

Ensures that servlets handle only one request at a time. This interface has no methods.

If a servlet implements this interface, you are guaranteed that no two threads will execute concurrently in the servlet's service method. The servlet container can make this guarantee by synchronizing access to a single instance of the servlet, or by maintaining a pool of servlet instances and dispatching each new request to a free servlet.

Note that SingleThreadModel does not solve all thread safety issues. For example, session attributes and static variables can still be accessed by multiple requests on multiple threads at the same time, even when SingleThreadModel servlets are used. It is recommended that a developer take other means to resolve those issues instead of implementing this interface, such as avoiding the usage of an instance variable or synchronizing the block of the code accessing those resources. This interface is deprecated in Servlet API version 2.4.

Author:
Various



Submit a bug or feature

Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

一看就知道只有菜鸟才干这么无知的事啦。

PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!