跨容器的会话复制如何工作?
我对一些时间细节感兴趣。例如,我在会话中放置一些容器,它可以保存不同的数据。我经常更改容器的内容。如何确保容器会话值在任何更改时都能跨节点复制?
I would be interested in some timing details. For example I place in session some container, which can keep different data. I do change of content of the container frequently. How can I assure that the container session value get replicates across nodes for any change?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你不需要确定;这是应用程序服务器的工作。
J2EE 规范不处理分布式组件之间的会话信息同步。
理论上,您所要做的就是编写线程安全的代码。在您的示例中,只需确保对容器的访问是同步的。如果您的应用程序服务器没有错误,那么您可以放心地假设会话信息已以无缝方式在所有节点上正确复制;如果您的应用程序服务器在会话同步方面有错误...那么...那么就没有什么是真正安全的了,现在就是了。
You don't need to make sure; that's the application server's job.
The J2EE specification doesn't deal with session-information synchronization amongst distributed components.
Theoretically, all you have to do is code thread-safe. In your example, simply make sure that access to the container is synchronized. If your application server is bug-free, then you can safely assume that the session information is properly replicated across all nodes in a seamless manner; if your application server has bugs around session synchronization... well... then nothing is really safe anymore, now is it.
应用服务器使用不同的策略来同步节点之间的会话信息。会话内容可以被认为是脏的并且需要同步
将数据放入会话中
从会话中获取数据
从会话获取数据分为两类:
获取结构化对象
获取标量对象或不可变对象
因此,如果通过修改结构化对象来间接修改会话数据,那么简单地从会话中重新读取它就可以确保对象内容得到复制。
Application servers use different strategies to synchronize session information between nodes. Session content can be considered as dirty and required synchronization at
put data in session
get data from session
get data from session falls in two categories as
get structured object
get scalar object or immutable object
So if session data get modified indirectly by modifying an structured object, then simple re-read it from session can assure that the object content got replicated.