According to the Java EE 6 Tutorial:
The EJB container is responsible for determining when to initialize a singleton session bean instance unless the singleton session bean implementation class is annotated with the javax.ejb.Startup annotation. In this case, sometimes called eager initialization, the EJB container must initialize the singleton session bean upon application startup. The singleton session bean is initialized before the EJB container delivers client requests to any enterprise beans in the application.
My RESTEasy application served by Thorntail doesn't use any EJB, but it uses @Startup, @Singleton and @PostConstruct annotations to run a long database update task during the initialization of the application server. It is something like this:
@Startup
@Singleton
public class StartupTask {
@PostConstruct
void init {
// database update task
}
}
Will my application be able to process HTTP requests before this task completes?
My question is similar to this one.
@Startup @Singleton StartupTask
is most definitely an EJB, so it is subject to the conditions that you have quoted above. You can circumvent the delay by moving the "database update task" logic to a second EJB with a void method annotated @Asynchronous and calling it from yourinit
method. – Torrez