Demonstrate Wildfly deployment order
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 2 commits ahead of briehman:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.mvn/wrapper
ear
webapp-one
webapp-three
webapp-two
.gitignore
README.md
mvnw
mvnw.cmd
pom.xml

README.md

Wildfly Deployment Order

Wildfly deployment scanner runs in parallel and it can be tricky to get it to deploy the application in the correct order.

Here is an EAR file containing three web applications. We would like to load webapp-one, followed by webapp-two, and finally webapp-three when the application starts. When it shuts down, the order should be reversed.

This example was developed and tested on Wildfly 10.0.0.Final.

Sample generated application.xml:

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" version="6">
  <display-name>ear</display-name>
  <initialize-in-order>true</initialize-in-order>
  <module>
    <web>
      <web-uri>webapp-one-1.0-SNAPSHOT.war</web-uri>
      <context-root>/one</context-root>
    </web>
  </module>
  <module>
    <web>
      <web-uri>webapp-two-1.0-SNAPSHOT.war</web-uri>
      <context-root>/two</context-root>
    </web>
  </module>
  <module>
    <web>
      <web-uri>webapp-three-1.0-SNAPSHOT.war</web-uri>
      <context-root>/three</context-root>
    </web>
  </module>
</application>

User-specified jboss-deployment-structure.xml in EAR's META-INF:

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
    <deployment>
        <dependencies>
            <module name="deployment.wildfly-deployment-order.ear.webapp-one-1.0-SNAPSHOT.war" />
            <module name="deployment.wildfly-deployment-order.ear.webapp-two-1.0-SNAPSHOT.war" />
            <module name="deployment.wildfly-deployment-order.ear.webapp-three-1.0-SNAPSHOT.war" />
        </dependencies>
    </deployment>
</jboss-deployment-structure>

The expected order should be:

  • webapp-one
  • webapp-two
  • webapp-three

Here is how Wildfly deploys the application:

18:46:04,291 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-8) WFLYSRV0027: Starting deployment of "wildfly-deployment-order.ear" (runtime-name: "wildfly-deployment-order.ear")
18:46:04,464 INFO  [org.infinispan.factories.GlobalComponentRegistry] (MSC service thread 1-3) ISPN000128: Infinispan version: Infinispan 'Mahou' 8.1.0.Final
18:46:04,463 INFO  [org.infinispan.factories.GlobalComponentRegistry] (MSC service thread 1-6) ISPN000128: Infinispan version: Infinispan 'Mahou' 8.1.0.Final
18:46:04,527 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) WFLYSRV0207: Starting subdeployment (runtime-name: "webapp-two-1.0-SNAPSHOT.war")
18:46:04,527 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-5) WFLYSRV0207: Starting subdeployment (runtime-name: "webapp-three-1.0-SNAPSHOT.war")
18:46:04,527 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-8) WFLYSRV0207: Starting subdeployment (runtime-name: "webapp-one-1.0-SNAPSHOT.war")
........

18:46:04,577 INFO  [org.jboss.ws.common.management] (MSC service thread 1-7) JBWS022052: Starting JBossWS 5.1.3.Final (Apache CXF 3.1.4) 
18:46:05,319 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 60) WFLYUT0021: Registered web context: /one
18:46:05,373 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 58) WFLYUT0021: Registered web context: /two
18:46:05,407 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 58) WFLYUT0021: Registered web context: /three
18:46:05,449 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 34) WFLYSRV0010: Deployed "wildfly-deployment-order.ear" (runtime-name : "wildfly-deployment-order.ear")


18:46:05,582 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9990/management
18:46:05,583 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9990
18:46:05,584 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Full 10.0.0.Final (WildFly Core 2.0.10.Final) started in 4818ms - Started 496 of 805 services (412 services are lazy, passive or on-demand)

........

18:46:18,622 INFO  [org.jboss.as.server] (Thread-2) WFLYSRV0220: Server shutdown has been requested.
18:46:18,666 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 25) WFLYUT0022: Unregistered web context: /three
18:46:18,685 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 25) WFLYUT0022: Unregistered web context: /two
18:46:18,694 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 25) WFLYUT0022: Unregistered web context: /one
........

18:46:18,697 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-1) WFLYUT0019: Host default-host stopping
18:46:18,699 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-1) WFLYJCA0010: Unbound data source [java:jboss/datasources/ExampleDS]
18:46:18,701 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-8) WFLYJCA0019: Stopped Driver service with driver-name = h2
18:46:18,730 INFO  [org.hibernate.validator.internal.util.Version] (MSC service thread 1-2) HV000001: Hibernate Validator 5.2.3.Final
18:46:18,819 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-8) WFLYUT0008: Undertow HTTP listener default suspending
18:46:18,820 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-8) WFLYUT0007: Undertow HTTP listener default stopped, was bound to 127.0.0.1:8080
18:46:18,822 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-8) WFLYUT0004: Undertow 1.3.15.Final stopping
18:46:18,827 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-4) WFLYSRV0208: Stopped subdeployment (runtime-name: webapp-one-1.0-SNAPSHOT.war) in 198ms
18:46:18,825 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-5) WFLYSRV0208: Stopped subdeployment (runtime-name: webapp-two-1.0-SNAPSHOT.war) in 197ms
18:46:18,831 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-7) WFLYSRV0208: Stopped subdeployment (runtime-name: webapp-three-1.0-SNAPSHOT.war) in 202ms
18:46:18,835 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-7) WFLYSRV0028: Stopped deployment wildfly-deployment-order.ear (runtime-name: wildfly-deployment-order.ear) in 209ms
18:46:18,841 INFO  [org.jboss.as] (MSC service thread 1-3) WFLYSRV0050: WildFly Full 10.0.0.Final (WildFly Core 2.0.10.Final) stopped in 199ms

You can see that the deployment scanner does not scan the WAR subdeployments in order. However, initialize-in-order being true means that the individual components in the deployment will be initialized in order.

Deployments and build deployment metadata is still scanned and parsed in parallel. Hence we see

18:46:04,527 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) WFLYSRV0207: Starting subdeployment (runtime-name: "webapp-two-1.0-SNAPSHOT.war")
18:46:04,527 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-5) WFLYSRV0207: Starting subdeployment (runtime-name: "webapp-three-1.0-SNAPSHOT.war")
18:46:04,527 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-8) WFLYSRV0207: Starting subdeployment (runtime-name: "webapp-one-1.0-SNAPSHOT.war")

This would have us believe that the order of deployment is

  • webapp-two
  • webapp-three
  • webapp-one

but this is not the case. In fact, if we restart the server several times, we might get a different order for the start of subdeployments.

If we inspect the order of registered contexts, we see that it is in the specified order:

18:46:05,319 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 60) WFLYUT0021: Registered web context: /one 
18:46:05,373 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 58) WFLYUT0021: Registered web context: /two 
18:46:05,407 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 58) WFLYUT0021: Registered web context: /three 

So the actual startup order is correct:

  • webapp-one
  • webapp-two
  • webapp-three

Similarly, when the application is being stopped, the contexts are unregistered in the reverse order:

18:46:18,622 INFO  [org.jboss.as.server] (Thread-2) WFLYSRV0220: Server shutdown has been requested.
18:46:18,666 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 25) WFLYUT0022: Unregistered web context: /three
18:46:18,685 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 25) WFLYUT0022: Unregistered web context: /two
18:46:18,694 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 25) WFLYUT0022: Unregistered web context: /one

which means shutdown order is as follows:

  • webapp-three
  • webapp-two
  • webapp-one

This is the desired startup and shutdown behavior for our application.