Specifications initialisation order

Hello everyone,

It is very good that you decided to open a forum. Really enjoying it so far.

I have a doubt which I think might be interesting to everyone that uses Payara Server or a Jakarta EE application server in general.

It goes around like this: a Jakarta EE + MicroProfile application can be built using several specifications that will all work together at runtime. Likely, the more complex the application, the more specifications it uses.

Some specifications, like JAX-RS, JPA, EJB, CDI and so on need certain classes to be scanned for annotations and likely need some actions from the app server to be validated, registered and/or initialized. Some even depend on others having being initialised (for example, consider a @Startup EJB that performs some action on a database using an EntityManager from JPA, certainly JPA needs to be active at that time).

So my question is:
consider an ordinary JakartaEE + MP application being deployed into a Payara Server Full.
This app is packaged in an .ear and has several modules, like this:

ear
persistence (jar) ( JPA @Entity beans)
dao (ejb) (EJB using EntityManager to CRUD entities)
ejbs (ejb) (multi purpose, for example used as clients to external services)
webservices_1 (war) (JAX-RS endpoints backed by EJBs or CDI beans, uses EJBs from dao module)
webservices_2 (war) (same as above, just to spice things up)
cdibeans (jar) (CDI beans, multipurpose)
health (war) (MP health specification endpoints, uses EJBs from dao module)

Now, whenever such application is deployed into a Payara Server we can see some of the steps being taken by looking at logs, for example:

2021-10-15T12:32:07.001+0100|INFO: com.company.persistence.EntityA actually got transformed
2021-10-15T12:32:07.098+0100|INFO: EclipseLink, version: Eclipse Persistence Services - 2.7.7.payara-p3
...
2021-10-15T12:32:26.277+0100|INFO: Portable JNDI names for EJB EntityDAO: [java:global/fc-application/dao/EntityDAO, java:global/ear/dao/EntityDAO!com.company.dao.EntityDAO]
...
2021-10-15T12:33:05.424+0100|INFO: Clustered CDI Event bus initialized
2021-10-15T12:33:05.632+0100|INFO: Loading EJBTimerService. Please wait.
...
2021-10-15T12:33:07.613+0100|INFO: Begin loading EntityA into object cache (this is a @Startup bean being initialised)
..

So, my question is:
admitting ALL specifications are used in an application,
what is the order of startup for each specification? (or bean container, or whatever it is)
and
what are the main tasks they must perform? (like CDI must validate Injection points and so on). In short, what happens when? (Does JPA scan kick in first, then EJB container, then JMS, then some other stuff?)

I know this has a potential for a somewhat long and technical response, but I think it is something really useful to know.

Thanks in advance!

1 Like

Hello Carlos,

this would be a very long technical paper, that would need to list a LOT of corner cases and require a lot of source code and spec reading, so it is not something one keeps in his head in great detail :wink:

But if you’d like to learn what paths is server taking for your specific application, I recommend enabling deployment tracing by setting system property “org.glassfish.deployment.trace” to true.
This will output timing in tabular form of the main steps the deployment command takes – looking at the usages of StructuredDeploymentTracing, it’s about 60 of them.

This will take you to specific components that participate in the deployment of your application.

Hello Patrik,

Thanks a lot! That does seem very interesting!
I will definitely check it out ASAP!

Maybe this is a nice idea for the Payara blog post series :wink:

Cheers