如何理解thread-safe

fingertiploneliness 2004-09-03 10:49:52
看struts in action时候有如下一段:
Actions are multithreaded; there is a single instance of any given Action subclass
per application. This means that Actions must be written to be thread-safe. When
you’re writing an Action subclass, the most important thing to remember is that
class properties cannot be used to share values between member methods. If
member methods are used, then all values must be passed through the method’s
signature. This passes the values through the stack, which is thread-safe.

谁懂,给解释一下(不是翻译),谢谢

...全文
69 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
treeroot 2004-09-03
  • 打赏
  • 举报
回复
其实就是Servlet的安全问题!!!
一个Action只有一个实例,当多个请求同时来的时候就会有多个线程共享这个实例.
所以你不应该使用类的实例变量,因为多个线程会共享它,所以会造成数据不正确,
对于Action中的方法也不应该引用类变量,而是把所有参数通过方法参数列表传递!
fantasyCoder 2004-09-03
  • 打赏
  • 举报
回复
http://community.csdn.net/Expert/topic/3330/3330891.xml?temp=.4090082

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧