Since stateless session bean instances are typically pooled, the time of the client's invocation of the create method need not have any direct relationship to the container's invocation of the PostConstruct/ejbCreate method on the stateless session bean instance.
I'm failing to understand this. Please help guys!
any method from your business interface does not need to relay on the PostConstruct method. Something like one bussines method will fail if the PostConstruct method(s) does not runs before.
I also think that the same logic for the pasivate feature (callback)
The stateless session beans are pooled. This means that:
1. You don't know when PostConstruct method is called
2. If an instance of your bean is reused for another client, the callback method will not be called
This means that your PostConstruct invokation cannot safely access to informations related to a specific request.
Stateless Session Beans are pooled. So think.. when the instances of bean class are getting created... as soon as you deploy the bean.
Now when you deploy the bean the container how it is creating the instance of bean class that is given to it ???
first it (container) loads the bean class
then it calls.. Class.newInstance() to create the object of bean...
then it calls ... setSessionContext if it is there..
then it calls... any method annotated with postConstruct or ejbCreate if it is there...
now bean pool is ready..
After this (it means after deployment of bean) client is free to call method on bean.
now even if a ejb 2.0/2.1 client... (their home interface has create method).. does lookup on homeObject and then calls create() on that home object (which according to ejb 2.0/2.1 specs is going to return reference of remote / local interface ..) the container is not going to create new bean instance so it is not going to call any postConstruct or ejbCreate method on bean.
That's what the specs is saying.
(There are some other details which you'll get to know later on as you progress)
I hope this is sufficient for you.
But don't anyone feel that the particular paragraph that I posted above form the specs are a bit confusing?
Yes, it may be difficult to understand if you are only used to EJB3's marvelous injection system, because things are done in the background. So "client's invocation of the create method" sounds obscure. If you know about EJB2.X, the way to use home interfaces to create beans, then what's written in the spec becomes clear.
[ September 04, 2008: Message edited by: Christophe Verre ]