基于线程的servlet本身就是多线程的,
只能让线程安全,却没办法实现servlet的单线程!
只能让线程安全,却没办法实现servlet的单线程!
解决方案 »
- ehcache的问题
- Struts2的问题求解
- Groovy与Grails讨论区
- 3个问题:注册类,轻量级和重量级J2EE框架的区别,什么是单态模型;
- 数据池c3po的问题
- 关于Tomcat发布的服务下载的问题,谢谢。
- 关于一个很简单TOMCAT启动命令的问题
- 收集近两年倒闭的软件公司,在南京
- 请问在STRUTS中能否引入CSS?
- 为什么while(rs.next)
- [求助],在整合Tomcat和Apache中,如何察看JK的jkstatus界面?
- 关于org.hibernate.HibernateException: No TransactionManagerLookup specified
2.4版本中已经不推荐使用了Deprecated. As of Java Servlet API 2.4, with no direct replacement. public interface SingleThreadModelEnsures 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.
默认值为trueisThreadSafe=false模式表示它是以Singleton模式运行。
该模式implements了接口SingleThreadMode,
该模式同一时刻只有一个实例,不会出现信息同步与否的概念。
若多个用户同时访问一个这种模式的页面,
那么先访问者完全执行完该页面后,后访问者才开始执行。isThreadSafe=true模式表示它以多线程方式运行。
该模式的信息同步,需访问同步方法(用synchronized标记的)来实现。
一般格式如下:
public synchronized void syncmethod(...){
if(...) {
wait();
}
notifyAll();
}