HttpSession线程是否安全,是否设置/获取属性线程安全操作? [英] Is HttpSession thread safe, are set/get Attribute thread safe operations?

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

问题描述

此外,正在设置的对象是否必须是线程安全的,以保证我们知道会话中存储的对象的状态是什么。

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如何不是线程安全的也可能有所帮助。

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

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