EJB 3.1 does have a standard @Singleton
annotation but EJB 3.0 doesn't. However, JBoss offers a JBoss extension to the EJB 3.0 spec to create a singleton with the @Service
annotation.
From the JBoss EJB 3.0 Reference Documentation:
JBoss provides a few extensions to the
EJB 3.0 spec. This chapter describes
those features here.
6.1. @Service EJBs
An extension offered by JBoss EJB 3.0
is the notion of a
@org.jboss.annotation.ejb.Service
annotated bean. They are singleton
beans and are not pooled, so only one
instance of the bean exists in the
server. They can have both @Remote
and
@Local
interfaces so they can be
accessed by java clients. When
different clients look up the
interfaces for @Service
beans, all
clients will work on the same instance
of the bean on the server. When
installing the bean it gets given a
JMX ObjectName in the MBean server it
runs on. The default is
jboss.j2ee:service=EJB3,name=<Fully qualified name of @Service bean>,type=service
You can override this default
ObjectName by specifying the
objectName
attribute of the
@Service
annotation.
References
- JBoss EJB 3.0 Reference Documentation
- JBoss EJB3 Tutorials