在EJB中,@Stateless超过@Singleton的真正用例是什么? [英] What is a real use-case for @Stateless over @Singleton in EJB

查看:1254
本文介绍了在EJB中,@Stateless超过@Singleton的真正用例是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我正确理解EJB,@Singleton实际上与纯Java中的Singleton相同,Spring中也是单例 - >一个实例,每个调用都会同时进行同一个实例。
@Stateless声明一个bean,可以(但不能)有多个实例,限制是同一个实例中只能有一个调用。正确的Sofar?
这仍然是我的servlet编程模型:在理论上,servlet容器允许制作servlet的多个副本,实际上我没有看到任何servlet容器。
所以假设我的代码中没有门,窗口或打印机的REALLY有限资源(如果我仍然可以用队列和东西来解决它),那么REAL实例是什么,@Stateless的用法是有利于@Singleton的使用。

if I understand EJB correctly, @Singleton is actually the same as Singleton in plain Java and also singleton in spring -> one instance, every call goes through the same instance concurrently. @Stateless declares a bean, that could (but must not) have multiple instance, with the limitation that only one call can be in an instance at the same time. Right sofar? This remains me on the servlet programming model: in theory servlet containers are allowed to make multiple copies of the servlet, in practice I haven't seen any servlet container to do so. So assuming I do not have REALLY LIMITED resources like doors, windows or printers in my code (and if I did I could still solve it with queues and stuff), what is the REAL example, where usage of @Stateless is advantageous over usage of @Singleton.


Leon

regards Leon

推荐答案

您可以拥有无​​状态bean的多个实例来增加吞吐量。

You can have multiple instances of a stateless bean to increase throughput.

另一方面,只有一个单例的实例。这样做的原因通常是在应用范围内共享状态,序列化资源访问等,这意味着锁定或同步。

On the other hand there is only one instance of a singleton. The reason for this is normally to share state in application scope, serializes access to resources etc., and this implies locking or synchronization.

所以如果你没有真正拥有单身,然后使用无国籍的豆。

So if you are not really having a singleton, then use a stateless bean.

如果你有一个无国籍的单身人士,没有什么区别。但是,如果你读单身,它有一个特殊的含义(=必须有一个使用单例模式的理由)。

If you have a "stateless singleton", there is no difference. But if you read "singleton", it has a special meaning by convention (= there must be a reason for using the singleton pattern).

这篇关于在EJB中,@Stateless超过@Singleton的真正用例是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆