无状态会话 bean 中的实例变量
我有一个无状态会话 bean,它有一个实例变量和两个公共方法。下面是它的伪代码。
private int instanceVar;
public void methodA(int x) {
instanceVar = x;
}
public void methodB() {
print instanceVar;
}
这两种方法都是从客户端依次调用的。客户端代码和无状态会话bean 部署在Websphere 上。据观察,当应用程序服务器的单个实例或具有 2 个应用程序服务器的集群时,从方法 B 打印的 instanceVar 值与方法 A 中的相同。但在具有 3 个应用程序服务器的环境中,打印的 instanceVar 值包含较旧的值。 谁能为我解释这种行为?
提前致谢!
问候, 苏杜
I have a stateless session bean which has an instance variable and two public methods.Below is pseudo code of it.
private int instanceVar;
public void methodA(int x) {
instanceVar = x;
}
public void methodB() {
print instanceVar;
}
Both the methods are called one after another from the client. The client code and stateless session bean are deployed on Websphere. Its observed that the value of instanceVar printed from methodB is same as in methodA when its a single instance of Application Server or a cluster having 2 Application servers. But in an environment having 3 Application servers, the value of instanceVar printed contains an older value.
Can anyone explain this behavior for me?
Thanks in Advance!
Regards,
Sudhu
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
即使在单个应用程序服务器上,EJB 容器也可以创建无状态会话 bean 的多个实例。因此,使用伪代码中所示的实例属性永远无法保证给出预期的结果。
Even on a single application server, the EJB container may create multiple instances of the stateless session bean. Therefore using an instance attribute as shown in your pseudo code will never be guaranteed to give the expected result.