• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Stateless Sessionbean ejbCreate() mtd

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It will be called before the instance goes to pool.
 
Parvathi G
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes you are right
 
Parvathi G
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Mini.....
 
reply
    Bookmark Topic Watch Topic
  • New Topic