我可以使用EJB 3.0制作自己的Singleton Stateless Bean吗? [英] Can i make my own Singleton Stateless Bean with EJB 3.0?

查看:93
本文介绍了我可以使用EJB 3.0制作自己的Singleton Stateless Bean吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,在EJB 3.1中,我们可以找到javax.ejb.Singleton注释,它可以确保此bean将成为单例.

Now, with EJB 3.1, we can find the javax.ejb.Singleton annocation that can ensure that this bean is going to be singleton.

有没有一种方法可以确保我在EJB 3.0中使用无状态bean并在我的代码中进行一些修改(使用关键字static或其他方式实现此目的...)

Is there a way that i can ensure singleton using stateless beans in EJB 3.0 with some modifications in my code (use of the keyword static, or other way to do that....)

推荐答案

如果您可以将@Stateless bean池的大小限制为正好1,那么您可以非常接近@Singleton.

If you're able to limit your @Stateless bean pool size to exactly 1, then you can get pretty close to an @Singleton.

效果就像有一个@Singleton,它使用@Lock(WRITE)进行所有调用(即不并发),并且不急于通过@Startup启动(它将首先启动访问).

The effect would be like having an @Singleton that uses @Lock(WRITE) for all calls (i.e. no concurrency) and does not eagerly startup via @Startup (it will start on first access).

如果您的平台可以选择紧急填充@Stateless豆池,那么您仍然可以得到@Startup的效果.

You might still be able to get the effect of @Startup if your platform has the option to eagerly fill @Stateless bean pools.

这篇关于我可以使用EJB 3.0制作自己的Singleton Stateless Bean吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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