O'Reilly logo

Java EE 7 Development with WildFly by Francesco Marchioni, Michal Matloka, Michal Cmil

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Developing singleton EJBs

As the name implies, javax.ejb.Singleton is a session bean that guarantees that there is at most one instance in the application.

Note

Besides this, singleton EJBs fill a well-known gap in EJB applications, that is, the ability to have an EJB 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 (before EJB 3.1) could only do with a load-on-startup servlet. EJB 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required