I have a simple stateless session bean named MySessionBean.
This bean has a @PostConstruct callback defined.
I have written a client for this bean using the @EJB DI annotation.
The @PostConstruct annotated method is not being invoked until i use the bean in the client, as follows, mySessionBean.someMethod();
My question : Will the container create the instance and put it in the pool as soon as i use the bean and invoke methods on it ? Why not in application server startup time ?
A stateless session bean instance’s life starts when the container invokes the newInstance method on the session bean class to create a new session bean instance. Next, the container injections the bean’s SessionContext, if applicable, and performs any other dependency injection as speciﬁed by metadata annotations on the bean class or by the deployment descriptor. The container then calls the PostConstruct lifecycle callback interceptor methods for the bean, if any. The container can perform the instance creation at any time—there is no direct relationship to a client’s invocation of a business method or the create method.
At any time... which may be at startup (e.g. creation of the pool, if there is one), when needed (first method invocation on that type of stateless bean) or at any other time. The important thing to remember is that you should not assume that it gets called immediately before the business method invocation.
[ September 21, 2008: Message edited by: Sergio Tridente ]