I was wondering… Let’s say that I have two stateless beans in ejb 3.1:
-
@Stateless
Class1@EJB MyUniqueInstanceBean uniqueBean1;
2.
@Stateless
Class2
@EJB MyUniqueInstanceBean uniqueBean2;
Are uniqueBean1 and uniqueBean2 guaranteed to be unique instances of MyUniqueInstanceBean?
If MyUniqueInstanceBean is Stateless it is not in your hands are calls to uniquebean1 and uniquebean2 actually calls to same instance. In EJB 3.1 specification this is told with following words:
If MyUniqueInstanceBean is Stateful, it is guaranteed that uniquebean1 and uniquebean2 do not refer to same instance. Again from specification:
If you are using Singleton, then both refer to same instance, because there is only one instance: