Hi, when we perform a JNDI lookup, does it return a reference to the Home interface or the reference to the class which implements the home interface which is created by the container during deployment?
The JNDI lookup returns a stub to the remote home object. This stub might not implement the home interface (as it might be an IIOP stub), so you must first narrow it and then cast it to the home interface. When we sometimes say that the home interface is returned, we actually mean that the stub returned from the lookup has been narrowed and cast to the home interface.
SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Joined: Oct 22, 2004
Hi, the below is my understanding of the whole EJB functionality.Correct me if iam wrong.
Initially to start with, we define home interface,remote interface and a bean class.
First , we have to get a reference to Home interface.During deployment,the server automatically generates a class which implements this home interface(Let this class be denoted by A).During JNDI lookup,the object to this class is returned.
CustomerHome cust = Context.lookup("Customer");
Customer remote = cust.create();
Like above,during deployment,the server generates a class which implements the remote interface(let this class be denoted by B).When the create method is called,an object to this class is created and its reference is returned.Also an instance to the bean class is created either by calling the beans constructor or by taking the instance from the pool.So the remote variable contains the reference to the class generated by the server.
Now when a method is called,
the control goes to the stub which performs marshalling.The stub transfers the data through network and the skeleton unmarshalls the arguements and calls the method in the class B.This inturn calls the actual bean implementation method.
This is my overall understanding of the working of EJB.Kindly correct me if iam wrong.
Joined: Sep 29, 2002
Also an instance to the bean class is created either by calling the beans constructor or by taking the instance from the pool.
For a stateless session bean or entity bean, the instantiation is typically done on server startup when a pool of instances is created for each bean type. In other words, bean creation is not related to what the client does. However, if client requests require more instances than are available, the container may create more instances up to the maximimum limit specified for the bean type.
For a stateful session bean, it's different in that the bean instance creation is done upon invocation of the client's create() method. In other words, stateful session beans are not pooled but created on client requests.
Joined: Oct 22, 2004
Hi, thanks for your reply.
In other words, stateful session beans are not pooled but created on client requests.
Can you kindly explain me why the instance creation for a stateful session bean happens only on the request and not pooled?