JBoss Community

Re: Singletons in a J2EE application server

created by Bernd Eckenfels in Beginner's Corner - View the full discussion

According to the Java EE 6 and EJB 3.1 Specification a Stateless Session Bean with the @Singleton Annotation is created once for an Application. If the Application is deployed on multiple VMs (in a Cluster) you have one Instance for each VM.

 

Of courxe you can have multiple different Singleton Beans.

 

If the locking and processing of a singleton bean is a problem for application performance, it could make sense to have multiple. But strictly speaking you wont have a real singleton anymore. This would be more like Statefull Session Beans. It is not addressed by the spec, but you could implement it conformant with the Spec by having multiple Singletons (same class, different name). In that case you would have to care for pooling andsynchronizing yourself.

Reply to this message by going to Community

Start a new discussion in Beginner's Corner at Community