• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Question regarding Lifecycle of STATELESS session bean.

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The EJB specification states that:

A stateless session bean instance�s life starts when the container invokes newInstance()on the session bean class to create a new instance. Next, the container calls setSession-Context() followed by ejbCreate() on the instance.
The container can perform the instance creation at any time�there is no relationship to a client�s invocation of the create() method.

Can somebody help me to understand about

"The container can perform the instance creation at any time�there is no relationship to a client�s invocation of the create() method."

I was under the impression that there is a relation between instance creation and the client�s invocation of the create() method.

Thanks for your help.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remember that stateless session beans are not tied to any specific client. The same stateless session bean can be served to multiple clients during its life period. Stateless beans go back to pool once it serves client and are ready to accept requests from other clients. But the stateful session beans are tied to a specific client. So it is created when the client calls the create method on stateful session bean home interface and will end once it served the client.

So, think about it. Why do you need to create stateless session beans when client calls create method if these beans can serve multiple clients. The container may decide to create a bunch of stateless beans during server startup for performance.

When client calls create method on a stateless session bean, the container creates EJBObject and associates it with the bean.

Hope this helps....
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Srini for your explanation.

About:

The container can perform the instance creation at any time�there is no relationship to a client's invocation of the create() method.



Srini said:

When client calls create method on a stateless session bean, the container creates EJBObject and associates it with the bean.



I guess the other order of events might also be possible:

When client calls create method on a stateless session bean, the container creates EJBObject, then creates the bean and associates the bean with the EJBObject.

-- Dan
 
Srini Madala
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes Dan.. You are right. The container may create EJBObject first and then the actual bean by calling new instance(), setSessiionContext(), and then ejbCreate().

As far as stateless session beans are concerned, it is up to the container, how it creates the beans. So we can not for certain assume that the bean will be created only when client calls create method on its home itnerface..
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand that the stateless session bean instance creation is not tied to any specific client.But I have a doubt here, Let's say, the container precreates the instances by running constructor,context and ejbCreate.
When it completes the ejbCreate method there won't be any EJBobject as the client wouldn't have invoked the create method in home interface.In that case, how it is possible to get a reference to EJBobject from ejbCreate method.Both in spec as well as in Certification book, it is mentioned that EJBobject reference can be retrieved thru context API from ejbCreate method.
 
reply
    Bookmark Topic Watch Topic
  • New Topic