简体   繁体   English

EJB:跨方法调用维护状态意味着什么?

[英]EJB: what does maintaining state across method calls mean?

"Stateful: These beans can hold client state across method invocations. This is possible with the use of instance variables declared in the class definition. The client will then set the values for these variables and use these values in other method calls." “有状态:这些bean可以在方法调用之间保持客户端状态。这可以通过使用在类定义中声明的实例变量来实现。客户端将设置这些变量的值并在其他方法调用中使用这些值。”

What does maintaining state across method calls mean ? 跨方法调用维护状态是什么意思?

sorry for the noobness of my question. 对不起,我的问题很笨拙。

Statefullness is bad when it comes to concurrency. 就并发而言,有状态性是很糟糕的。 For Example you have one Statefull Bean, UserRegistrationBean which stores email then if two users try to register at the same time in a race condition one user overwrite the other one's email. 例如,您有一个Statefull Bean,即UserRegistrationBean,它存储电子邮件,然后,如果两个用户在竞争条件下尝试同时注册,则一个用户会覆盖另一个人的电子邮件。

Statefullness requires synchronized access to the state which is costly. 有状态性要求同步访问昂贵的状态。

You can think of it as the HttpSession on a web application. 您可以将其视为Web应用程序上的HttpSession。 What you save on HttpSession is available across different requests to the web server. 您保存在HttpSession上的内容可用于对Web服务器的不同请求。 Likewise what you store as class variables in a session EJB is available across different method invocations done on the same session EJB. 同样,在会话EJB中作为类变量存储的内容可在同一会话EJB上进行的不同方法调用之间使用。

Refer: 参考:

Lookup returns new instance of Stateful session bean http://www.javaworld.com/article/2071724/java-web-development/ejb-fundamentals-and-session-beans.html 查找返回有状态会话bean的新实例 http://www.javaworld.com/article/2071724/java-web-development/ejb-fundamentals-and-session-beans.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM