...
Note that @DependsOn is only required (and should only be used) if a Singleton uses another Singleton in its @PostConstruct method or @PreDestroy method. Simply having a reference to another Singleton and using it in other business methods does not require an @DependsOn declaration. The @DependsOn allows the Container to calculate the correct startup order and shutdown order so that it can guarantee the Singletons you need are available in your @PostConstruct or @PreDestroy methods. All Singletons will automatically be available to your business methods regardless if @DependsOn is used. Because of the greater chance of creating circular dependencies, it is better not to use the @DependsOn annotation "just in case" and should only be used when truly needed.
XML and Annotation Overriding
Singletons can be declared in the ejb-jar.xml as follows:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<session>
<ejb-name>MySingletonBean</ejb-name>
<ejb-class>org.superbiz.MySingletonBean</ejb-class>
<session-type>Singleton</session-type>
<load-on-startup>true</load-on-startup>
<depends-on>
<ejb-name>SingletonFoo</ejb-name>
<ejb-name>SingletonBar</ejb-name>
</depends-on>
</session>
|
Example Code
Wiki Markup |
---|
{snippet:url=openejb3/examples/simple-singleton/src/main/java/org/superbiz/registry/ComponentRegistryBean.java|lang=java} |
...