Hi Sanjeev, This is true that the ejbCreate() is not called for every SLSB. but we cant give the initializations in the setSessionContext() method, beacuase we are not in control of the method signature. This implies that we cant throw a checked exception in the setSessionContext. You can still throw a runtime exception and take the bean out of the pool. But wont we have a case when initializing that we throw a checked exception. Although i never came across a need for this. But i think intializing in ejbCreate() method will do the work. We dont need to intitialize the bean again and again. We can think of SLSB as a thread working on the same state. The state is the member variables of the SLSB, and we need to initialize this only once.
Regards Cherry (Siju) --- Sanjeev Verma <[EMAIL PROTECTED]> wrote: > Hi guys > I have been following this thread for some time now, > and everyone seems > to say that the ejbCreate() will get fired at the > moment the SLSB goes > into the method ready pool. > > I think that is not the case. Try this: using > Weblogic 5.1, create a > pool of SLSBs at startup of the Server by specifying > the number in the > initial-beans-in-free-pool tag of the > weblogic-ejb-jar file. Keep some > SOP (System.out.println()) command in the > ejbCreate() method. You will > find that the SOP will not be printed. > > Next try this: Give an additional SOP in the > setSessionContext() method. > This command will execute the number of times you > have mentioned in the > initial-beans-in-free-pool tag. > > I think this should lead to the conclusion that in > SLSB, we should carry > out all our initialization work in the > setSessionContext() method, which > will get executed whenever the bean instance gets > created. The > ejbCreate() method may or may not get fired on the > instance. > > Next read this (Ctrl-v from Mastering EJB Ed Roman) > and see figure on > page No. 684 of the same book > > <quote> > When Are My Beans Created? > We've learned that the container is responsible for > pooling stateless > session beans. The container creates and destroys > beans when the > container decides it's the right time to resize its > pool. Your client > code is absolutely not responsible for creating > beans. A client deals > with the networked bean wrapper, called the EJB > object. The EJB object > is part of the container, and it is responsible for > retrieving beans > from a pool to service client requests. But if the > container is > responsible for bean life cycle, then why does the > home interface > specify create() and remove() methods? What you must > remember is that > these methods are for creating and destroying EJB > objects. This may not > correspond to the actual creation and destruction of > beans. The client > shouldn't care whether the actual bean is created or > destroyed-all the > client code cares about is that the client has an > EJB object to invoke. > The fact that beans are pooled behind the EJB object > is irrelevant. So, > when debugging your EJB applications, don't be > alarmed if your bean > isn't being created or destroyed when you call > create() or remove() on > the home object. Depending on your container's > policy, your stateless > session beans may be pooled and reused, with the > container creating and > destroying at will. </quote> > > I am not very sure that ejbRemove() will be called > at the time when the > bean is removed from the ready pool. Can someone > shed some light?? > > Please comment > > Regards > Sanjeev > > -----Original Message----- > From: Mohit Agrawal [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, November 07, 2001 11:59 AM > To: [EMAIL PROTECTED] > Subject: Re: [Re:State in Stateless Session Bean] > > Hi Gavin > Instance variables like db connection or socket > connections etc which > can be used by any client irrespective of state can > be initilized in > ejbCreate(). > > U can open connectin in ejbCreate() and can destroy > it in ejbRemove(). > While bean instance is in pool, connection will > remain open and will be > accessible to all. > > Following code snipt may help u :- > > public void ejbCreate() > { > try > { > captureJDBCConnection(); > } > catch(Exception e) > { > e.printStackTrace(); > } > } > > public void ejbRemove() > { > try > { > releaseJDBCResources(); > } > catch(Exception e) > { > e.printStackTrace(); > } > } > > > > Regards > Mohit > > -------Original Message------- > > From: Gavin Selvaratnam > Date: Wednesday, November 07, 2001 11:43:20 AM > To: Mohit Agrawal > Subject: Re: [Re:State in Stateless Session Bean] > > Hi Mohit, > Well what I want to do is initialize a DB conection > in a SLSB. But I > dont want to create an destroy the connection for > each method invoked, > as > it will be a performance degrader. I want to keep > the connection in the > SLSB and when the SLSB is destroyed the connection > should be destroyed. > > Thanks, > Gavin > > > > Mohit Agrawal > <magrawal@ARGU To: Gavin Selvaratnam > <[EMAIL PROTECTED]> > SOFT.COM> cc: > Subject: Re: [Re:State in Stateless Session > 11/07/2001 Bean] > 10:32 AM > > > > > > > hi gavin, > Actually u dont have any control over the state of > instance variabls of > a > SLSB. U can only initilize once in ejbCreate() which > will be called the > time of instance creation. After that u cannot > control the state of > instance variables in SLSB. > Thats why it is not suggested to use client state > specific instance > variables in SLSB. > What is ur actual problem, if tell in detail, it > might be possible to > find > some alternative solutions. > > Regards > Mohit > > ======================================================================== > === > To unsubscribe, send email to [EMAIL PROTECTED] > and include in the > body > of the message "signoff EJB-INTEREST". For general > help, send email to > [EMAIL PROTECTED] and include in the body of the > message "help". > === message truncated === __________________________________________________ Do You Yahoo!? Find a job, post your resume. http://careers.yahoo.com =========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff EJB-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
