aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes  Stateless Sessionbean ejbCreate() mtd Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark " Stateless Sessionbean ejbCreate() mtd" Watch " Stateless Sessionbean ejbCreate() mtd" New topic
Author

Stateless Sessionbean ejbCreate() mtd

Parvathi G
Greenhorn

Joined: Dec 17, 2005
Posts: 28
Hi,
I am having confusion in ejbCreate() method call for a Stateless bean.
Container will create a pool of Stateless Session Beans(the setSessionContext() mtd call is decided by the Container).
When client calls the Home create() mtd, the Container returns the EJBObject but at this time, the bean is still in the pool, there is no link between the EJBObject and Bean. The bean is associate to EJBObject only when the client invokes any business mtd on the EJBObject.
So, when will be ejbCreate() mtd in the Bean is executed. Is it when the Container creates the bean or else when the client invokes the Home.create().

Entity Beans also pooled by the Continer. So, for this ejbCreate() is called when the client invokes Home.create() method.

Please clarify me on this....

Thanks & Regards,
Parvathi.
KasiMurugan Ramasamy
Ranch Hand

Joined: Jan 30, 2005
Posts: 125
It will be called before the instance goes to pool.


Thanks & Regards
Kasimurugan (SCJP1.4, SCBCD1.3), Preparing SCWCD1.4
Parvathi G
Greenhorn

Joined: Dec 17, 2005
Posts: 28
Hi,

For session bean the ejbCreate() mtd is called only once rite.
So, for stateless bean it is called before the instance go to pool.
Then for statefull session bean is it every time bcoz the bean is specify to the client.

Please correct if I am wrong.

Thanks & Regards,
Parvathi.
Mini Sarin
Ranch Hand

Joined: Apr 07, 2006
Posts: 31
Hi Parvati,

The following is my understanding of the session bean lifecycle. Hope this helps you.

For a stateful session bean instance:

1. A client invokes create on the home. The container invokes newInstance on the session bean class to create a new session bean instance. Next, the container calls setSessionContext and ejbCreate and returns the session EJBObject reference to the client.

2. Now the client can invoke business methods on the instance. Now if the bean is inactive for some time, container will call ejbPassivate. Again if client invokes business method, ejbActivate will called.

3. The instance remains in memory as long as the client is invoking business methods. If the client calls remove() on the bean or if timeout occurs, the instance will be removed, so will the associated session object.

Now if the client wants the bean again, he has to invoke create again. So for the lifetime of a session bean, ejbCreate will be called only once.

Talking about stateless session bean,

1. the life of a stateless session bean starts when the container invokes the newInstance method on the session bean class. Next the container calls setSessionContext followed by ejbCreate on the instance. The container can do the above any time, independent of a client invoking create. The instance will now be in the pool.

2. When the client invokes create, only an EJBObject will be created which will be later linked to a bean instance in the pool to service client requests.

3. Similarly, the container can invoke ejbRemove on a bean instance at any time independent of a remove call from the client.

So, in case of stateless bean also, ejbCreate is invoked only once in a bean's life cycle.

- Mini (preparing for SCBCD)
KasiMurugan Ramasamy
Ranch Hand

Joined: Jan 30, 2005
Posts: 125
Yes you are right
Parvathi G
Greenhorn

Joined: Dec 17, 2005
Posts: 28
Thank you Mini.....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Stateless Sessionbean ejbCreate() mtd