• 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

Invoking Nonexistent Stateful Session Bean

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have set up a stateful session bean. Later I will invoke it from a servlet. Suppose the container did not create the stateful session bean, or the stateful session bean timed out. What happens when the servlet tries to invoke it later? Does the invoking method cause an exception? Or does the inkoing method cause the container to redo the life cucle again? If so, how?
I could not find the answer in any of my textbooks.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When the stateful session bean times out, the container will swap it out to hard disk which is known as passivation. And the container will swap it into memory which is known as activation, when you later on invoke the ejb object which is associated with this session bean instance.
I hope this will make you clear
 
pchen
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply. I guess that my concern is that how does the EJB container behave when the servlet invokes a method on a non-existent stateful session bean. There is NO HttpSession state reference for the stateful session bean. Will the method call automatically cause the EJB container initiate a life cycle through a new naming service invocation, etc.? Or will there be an exception error because of a method call to nothing?
 
wei wu
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all, you should know these terms,
1> home object-- an instance of home interface implementation class which is generated by container. Every EJB class has only one home object.
2> home stub -- since home object is remote object, it must have stub.
3> ejb object -- an instance of your remote interface implementation class which is generated by container also. ejb object is created by home object.
4> ejb object stub -- the stub of an ejb object.
The situation you concerned doesnot exist. First of all, you call create(...) method on home stub which returns an ejb object stub. The ejb object is associated with an session bean instance. Your method call on ejb object stub will be forwarded to ejb object and then forwarded to the associated session bean instance.
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by wei wu:
When the stateful session bean times out, the container will swap it out to hard disk which is known as passivation.


That's wrong. The container passivates stateful session beans only if they are not used for a while and it needs more memory resource to fullfill other requests.
If a stateful session bean times out the container removes it and you get an object not exist exception or something similar.
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I guess that my concern is that how does the EJB container behave when the servlet invokes a method on a non-existent stateful session bean. There is NO HttpSession state reference for the stateful session bean. Will the method call automatically cause the EJB container initiate a life cycle through a new naming service invocation, etc.? Or will there be an exception error because of a method call to nothing?


You get NoSuchObjectException thrown if the client tries to invoke a method by using a stub to the EJB Object which is not usable - gone, corrupt, whatever.
You get RemoteException thrown if the client, using a stub to a valid EJB Object, invokes a business method on a bean that's already been removed.
 
wei wu
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to Peter Storch, you are right
 
Fire me boy! Cool, soothing, shameless self promotion:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic