Developing singleton EJBs
As the name implies, javax.ejb.Singleton
is a session bean that guarantees that there is one instance in the application, at most.
Note
Besides this, singleton EJBs fill up a well-known gap in EJB applications, that is, the ability to have an EJB that is notified when the application starts and also when the application stops. So, you can do all sorts of things with an EJB that you previously could only do with a load-on-startup servlet. It also gives you a place to hold data that pertains to the entire application and all the users using it, without the need for static class fields.
In order to turn your EJB into a singleton, all that is needed is to apply the @
javax.ejb.Singleton
annotation on top of it.
Note
A singleton ...
Get JBoss AS 7 Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.