论坛首页 Java企业应用论坛

一个关于DispatchAction中私有变量的问题

浏览 7755 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2004-11-01  
如果结合Spring , 你把Action当作Bean交给 Spring 来管理,singleton="false" 就可以解决呀!
0 请登录后投票
   发表时间:2004-11-01  
robbin 写道
Struts的Action不是线程安全的。

Struts文档中下面的话:
Remember the following design guidelines when coding Action classes:

Write code for a multi-threaded environment - The controller servlet creates only one instance of your Action class, and uses this one instance to service all requests. Thus, you need to write thread-safe Action classes. Follow the same guidelines you would use to write thread-safe Servlets. Here are two general guidelines that will help you write scalable, thread-safe Action classes:
Only Use Local Variables - The most important principle that aids in thread-safe coding is to use only local variables, not instance variables, in your Action class.
详细内容:
http://struts.apache.org/userGuide/building_controller.html

Struts和WW2的比较
Struts:
Struts Actions must be thread-safe because there will only be one instance to handle all requests. This places restrictions on what can be done with Struts Actions as any resources held must be thread-safe or access to them must be synchronized.
ww2:
WebWork Actions are instantiated for each request, so there are no thread-safety issues. In practice, Servlet containers generate many throw-away objects per request, and one more Object does not prove to be a problem for performance or garbage collection.
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics