How to determine the load order of MBeans in JBoss 5?

In JBoss 5, the load order of MBeans is determined by the dependencies between MBeans and the order in which they are defined in the jboss-service.xml file.

MBeans can depend on other MBeans, and the MBean server will ensure that the dependencies are satisfied before starting an MBean. For example, if MBean A depends on MBean B, then MBean B will be started before MBean A.

The jboss-service.xml file is an XML configuration file that defines the MBeans that make up the JBoss application server. The MBeans are defined in the file in the order in which they should be started.

To determine the load order of MBeans in JBoss 5, you can examine the jboss-service.xml file and look at the dependencies between MBeans and the order in which they are defined. You can also use the JMX console to view the MBeans and their dependencies.

For example, here is an HelloWorldService that depends on the application.ear:

  <mbean code="sample.HelloWorldService" name="sample:service=HelloWorld,id=1">


You can also apply the same criteria to other packages such as a JAR file:

  <mbean code="sample.HelloWorldService" name="sample:service=HelloWorld,id=1">


How to determine the order of load between Services?

A typical use case would be that the EJB Timer service, which is configured in the server deploy directory with the ejb3-timer-

Supposing you want your Timer service to be started after that your applications (a Web application and an EJB application) are deployed as shown here:

jboss as service mbean depends

All you have to do is adding a <depends> attribute to the EJB3TimerService MBean. Open the ejb3-timer-service.xml. This file already contains some dependancies on other services, we will add here our deployment dependency:
    <mbean code="org.jboss.ejb3.timerservice.quartz.jmx.EJB3TimerService" name="jboss.ejb:service=EJB3TimerService">
        <depends optional-attribute-name="DataSource">jboss.jca:service=DataSourceBinding,name=DefaultDS</depends>
    <!-- WEB dependency -->
    <!-- EJB dependency -->
        <attribute name="Properties">
                 <!-- commented for brevity -->

As you can see, adding a dependency for a Web application is quite easy, you have just to add the WebContext name of the application. Dependency of an EJB application is also easy, you have just to state some additional information like the EJB Class name and the Service type (EJB3) as it falls in the generic jboss.j2ee tree.