HttpSession 线程安全,set/get 属性线程安全操作吗? [英] Is HttpSession thread safe, are set/get Attribute thread safe operations?

查看:57
本文介绍了HttpSession 线程安全,set/get 属性线程安全操作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此外,被设置的对象是否必须是线程安全的,以保证我们知道会话中存储的对象的状态是已知的.

Also, does the object that is being set have to be thread safe in order to guarantee that we know what the state of the object stored in session is known.

另外,我在网上阅读了一些建议使用的内容:

Also, I was reading on the web that some suggest using:

synchronized(session) {
  session.setAttribute("abc", "abc");
}

这是一个有效的建议吗?

Is this a valid suggestion?

推荐答案

不,它们不是线程安全的,根据 IBM - Java 理论与实践:所有有状态的 Web 应用程序都被破坏了吗?.您需要同步.

No, they are not thread safe, according to IBM - Java theory and practice: Are all stateful Web applications broken?. You need to synchronize.

HttpSession 不是线程安全的来自 Java Ranch 的可能也有帮助.

How HttpSession is not thread safe from Java Ranch might be helpful, too.

这篇关于HttpSession 线程安全,set/get 属性线程安全操作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆