In the context of a Java EE 6
application run on WebSphere 8.0
, I need to execute a number of startup tasks before any business method can be executed. Using a @Startup
, @Singleton
bean for this purpose seems like a promising solution. However, it is not entirely clear to me how exactly the application lifecycle would look like. The EJB 3.1 spec states the following:
By default, the container is responsible for deciding when to initialize a Singleton bean instance. However, the bean developer can optionally configure the Singleton for eager initialization. If the Startup annotation appears on the Singleton bean class or if the Singleton has been designated via the deployment descriptor as requiring eager initialization, the container must initialize the Singleton bean instance during the application startup sequence. The container must initialize all such startup-time Singletons before any client requests are delivered to any enterprise bean components in the application.
In the last sentence, what exactly constitutes initialization? Will the container wait for the
@PostConstruct
method of the@Startup
bean to return before making enterprise beans available to client requests?Speaking of client requests, do scheduled executions of an EJB method with the
@Scheduled
annotation count as one in this context?
I need to guarantee that some code is executed on application startup before any of the business methods in any of the application's various EJBs can be run, be it through client calls or scheduled executions. Does running the startup code inside the @PostConstruct
method of a @Singleton
, @Startup
bean provide such a guarantee? If not, is there any other way to guarantee this behavior?
@PostConstruct
methods. – Subdominant@PostConstruct
methods and preventing calls to all beans while any@Startup
bean is in its@PostConstruct
method, which is the behavior required by the spec. – Spearhead@PostConstruct
, I believe he was wondering whether@PostConstruct
is part of initialization or not. – Subdominant@PostConstruct
methods. – Spearhead