The javax.ejb.Singleton annotation javax.ejb.Singleton used to indicate that the enterprise bean implementation class is a single-line bean session.
This information is intended to indicate an ejb container, not to create multiple instances of this bean and create only one instance. Otherwise, it is a regular bean class. More details here:
http://docs.oracle.com/javaee/6/tutorial/doc/gipvi.html
You do not need to create a static variable and do all the related things to make it singleton. Just write a regular bean, as indicated here, and the container will take care of an instance of only its object:
@Startup @Singleton public class StatusBean { private String status; @PostConstruct void init { status = "Ready"; } ... }
source share