A stateless session bean instance�s life starts when the container invokes newInstance()on the session bean class to create a new instance. Next, the container calls setSession-Context() followed by ejbCreate() on the instance. The container can perform the instance creation at any time�there is no relationship to a client�s invocation of the create() method.
Can somebody help me to understand about
"The container can perform the instance creation at any time�there is no relationship to a client�s invocation of the create() method."
I was under the impression that there is a relation between instance creation and the client�s invocation of the create() method.
Remember that stateless session beans are not tied to any specific client. The same stateless session bean can be served to multiple clients during its life period. Stateless beans go back to pool once it serves client and are ready to accept requests from other clients. But the stateful session beans are tied to a specific client. So it is created when the client calls the create method on stateful session bean home interface and will end once it served the client.
So, think about it. Why do you need to create stateless session beans when client calls create method if these beans can serve multiple clients. The container may decide to create a bunch of stateless beans during server startup for performance.
When client calls create method on a stateless session bean, the container creates EJBObject and associates it with the bean.
Yes Dan.. You are right. The container may create EJBObject first and then the actual bean by calling new instance(), setSessiionContext(), and then ejbCreate().
As far as stateless session beans are concerned, it is up to the container, how it creates the beans. So we can not for certain assume that the bean will be created only when client calls create method on its home itnerface..
I understand that the stateless session bean instance creation is not tied to any specific client.But I have a doubt here, Let's say, the container precreates the instances by running constructor,context and ejbCreate. When it completes the ejbCreate method there won't be any EJBobject as the client wouldn't have invoked the create method in home interface.In that case, how it is possible to get a reference to EJBobject from ejbCreate method.Both in spec as well as in Certification book, it is mentioned that EJBobject reference can be retrieved thru context API from ejbCreate method.