为什么要池化无状态bean?
通常我们对业务/dao层使用单例实例。对于 EJB,池化无状态会话 Bean 背后的原因是什么?
Normally we use singleton instance for business / dao layer. What is the reason behind pooling stateless session beans in case of EJBs?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
名称中的“无状态”指的是会话会话状态,即在 bean 调用之间持续存在的状态,并在会话期间保留。然而,无状态会话 bean 仍然允许有实例变量。这些实例变量不应与对话状态相关,而是在客户端之间“共享”。
换句话说,无状态会话 Bean 不能保证线程安全。
因此,容器应确保一次只有一个线程正在执行无状态会话 Bean 的给定实例,因此需要一组线程。
The "stateless" in the name refers to session conversation state, i.e. state that persists between invocations of the bean, retained for the duration of the session. However, stateless session beans are still permitted to have instance variables. Those instance variables should not relate to the conversation state, but are "shared" between clients.
In other words, stateless session beans are not guaranteed thread safe.
As a result, the container should ensure that only one thread is executing a given instance of a stateless session bean at one time, hence the need for a pool of them.