Embedding a Singleton Session Bean in a Beanless Session

Is it allowed (and good practice) to store some general information in our application using a Singleton Bean session inside a session without a Bean state?

SSB will be introduced in SLSB.

@Stateless public class MySLSB { @Inject MySSB mySSB; 

-

 @Singleton @Lock(READ) public class MySSB implements Serializable { private static final long serialVersionUID = 1L; 
+5
source share
2 answers

This is more than allowed. Using Singleton injections in your stateless or statefull EJBs will allow you to invoke business methods on your SSB in your SLSB. One of the trivial advantages is the use of simultaneous SSB capabilities. In your example, all calls of your method to you SSB will be blocked in Read, and this means that all your threads will access your SSB methods in read mode if the thread does not hold the Write lock.

+6
source

Yes, it is allowed, and I think it is good practice. The projects I'm working with have global properties read from a file. This is good practice because you store it in one place, and if you need this information, you only need to enter your singleton bean. I think this is a good example of the Hollywood principle.

+1
source

All Articles