• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question regarding a session bean's life cycle ...

 
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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 ?

Please advice,

Best regards,
 
Ranch Hand
Posts: 329
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It depends on the EJB Container's implementation. Section 4.5.1 of the ejb core specification states:


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 specified 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 ]
 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks
reply
    Bookmark Topic Watch Topic
  • New Topic