Is it true ? I have given the sample program for my doubt /

1. I ran a simple Stateless Session Bean program and I found when I try to call a method on remote interface, that time only the container calls setSessionContext() and ejbCreate() is called, else it is not called by the container, is it true ?
example:
my client program
               HInter home = (HInter) iCtx.lookup("First");
               System.out.println("After returning home handle and before calling create method");
               RInter rem = home.create();
               System.out.println("After returning remote refernece handle and after calling create method");
               System.out.println("Client programs end---");
when i run this program, the container never calls the create and setsessioncontext method
but
modified client program
HInter home = (HInter) iCtx.lookup("First");
               System.out.println("After returning home handle and before calling create method");
               RInter rem = home.create();
               System.out.println("After returning remote refernece handle and after calling create method");
               String test = rem.sayHello();
               System.out.println("Client programs end---"+test);
               System.out.println("Client programs end---");
when i run this program, the container calls the create and setsessioncontext method of the bean class

1. I ran a simple Stateless Session Bean program and
I found when I try to call a method on remote
interface, that time only the container calls
setSessionContext() and ejbCreate() is called, else
it is not called by the container, is it true ?
Yes, but the exact behavior depends on the ejb container implementation. What you're observing is that for stateless session beans, the ejb container has a lot of flexibility as to when it instantiates the actual bean instances. For each bean instance, setSessionContext and ejbCreate are guaranteed to be called once before any business method is invoked on that instance. What many containers do, including our implementation in the Java EE SDK, is to wait until the actual business method is called on the bean to instantiate the bean instance. Essentially that means that in many ejb container implementations, Home.create() for stateless session beans is treated as a no-op.
--ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

Maybe you are looking for