servlet线程安全吗?

    xiaoxiao2021-04-19  89

    servlet  http://m.blog.csdn.net/article/details?id=8974590 springMVC http://m.blog.csdn.net/article/details?id=52180476 struts1/struts2  http://www.cnblogs.com/firstdream/p/5589314.html

    spring mvc与struts2 https://rc.mbd.baidu.com/rmc8xux

             (1)     Servlet的线程安全问题只有在大量的并发访问时才会显现出来,并且很难发现,因此在编写Servlet程序                  时要特别注意。线程安全问题主要是由实例变量造成的,因此在Servlet中应避免使用实例变量。如果应用程                  序设计无法避免使用实例变量,那么使用同步来保护要使用的实例变量,但为保证系统的最佳性能,应该                  同步可用性最小的代码路径。

    (2)springmvc的controller是singleton的(非线程安全的),这也许就是他和struts2的区别吧。 springmvc线程安全有几种解决方法: 1、在Controller中使用ThreadLocal变量 2、在spring配置文件Controller中声明 scope="prototype",每次都创建新的controller 所以在使用spring开发web 时要注意,默认Controller、Dao、Service都是单例的。

    (3)struts2的action是线程安全的,struts1的action不是线程安全的

    转载请注明原文地址: https://ju.6miu.com/read-675960.html

    最新回复(0)