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

家住魔仙堡 提交于 2019-12-08 07:51:09

问题


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


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/3844720/can-i-make-my-own-singleton-stateless-bean-with-ejb-3-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!