无状态会话 Bean 与普通类相比能提供什么?
与具有相同方法的常规类相比,无状态会话 Bean 会提供什么?似乎有状态会话 bean 可以开箱即用地分发,并且容器将确保状态对于任何地方的客户端来说都是相同的。使用无状态会话 bean 可以提供哪些普通类无法提供的功能?
如果您有分布式环境,您的 EJB 层是否可以进行故障转移?在我看来,您可以获得无状态会话 bean 的本地或远程实例,如果我只为我的应用程序使用一台服务器,因此从不使用远程接口,有什么好处吗?
What would a stateless session bean provide over just a regular class that has the same methods? It seems that a stateful session bean can be distributed out of the box and the container will make sure that the state looks the same to clients anywhere. With a stateless session bean what is provided that you would not get with a normal class?
Is it just that your EJB tier can fail over if you have a distributed environment? It seems to me that you can get a local or remote instance of a stateless session bean, if I only use one server for my application and thus never use the remote interface is there any benefit?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
EJB 为您提供声明性安全性、事务和远程处理。当您调用 EJB 的某个方法时,您实际上会通过一堆提供上述功能层的拦截器。
普通的旧 Java 对象不会做任何事情。当然,如果您不需要其中任何一个,那么 EJB 就不是必需的。
EJBs give you declarative security, transactions and remoting. When you call one of the EJB's methods, you actually pass through a stack of interceptors that provide the above layers of functionality.
A Plain Old Java Object wouldn't do any of that. Of course, if you don't need any of that, then EJBs are not necessary.
无状态会话 Bean 向应用程序容器提供有关其所提供服务的意图的信息。由于它是无状态的,应用程序容器可以随时决定销毁该 bean 并在下次需要时重新创建它。
如果没有这些语义,应用程序容器就无法优化您的应用程序的速度/内存/其他方面。因此,尽管无状态会话 Bean 大多数类似于 POJO,但它们为应用程序服务器提供了一些额外的“提示”。
如果您了解如何使用 EJB3 规范来实现无状态会话 Bean,您会发现它与普通 POJO(除了附加注释之外)有很多相似之处。
A stateless session bean provides the application container with knowledge about the intent of the services it provides. As it is stateless, the application container can decide at any moment in time to destroy the bean and recreate it the next time it is needed.
Without these semantics, the application container cannot optimize your application for speed/memory/whatever. So, although stateless session beans mostly resemble POJOs, they provide some additional "hints" for the application server.
If you would look at how stateless session beans should be implemented using the EJB3 specification, you would see much resemblance between it and a normal POJO (aside the additional annotations).