开发者

Can i make my own Singleton Stateless Bean with EJB 3.0?

开发者 https://www.devze.com 2023-01-18 16:43 出处:网络
Now, with EJB 3.1, we can find the javax.ejb.Singleton annocation that can ensure that this bean开发者_开发问答 is going to be singleton.

Now, with EJB 3.1, we can find the javax.ejb.Singleton annocation that can ensure that this bean开发者_开发问答 is going to be singleton.

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....)


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

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).

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


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....)

No, nothing standard. Your container might provide some specific extensions though (e.g. JBoss has a proprietary @Service annotation).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号