Win a copy of Event Streams in Action this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Questions on Life Cycle of a Stateful Session Bean Instance

 
Ranch Hand
Posts: 634
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Source:EJB 3.1 Spec.




4.6 Stateful Session Bean State Diagram

While the instance is in the passivated state, the container may remove the session object after
the expiration of a timeout specified by the Deployer. All object references and handles for the
session object become invalid.

If a client invokes a session object whose session bean instance has been passivated, the container will activate the instance. To activate the session bean instance, the container restores the
instance’s state from secondary storage and invokes the PostActivate method for the



The First paragraph says that "While the instance is in the passivated state, the container may remove the session object"

As far I understand,Instance is a reference to Object.
If instance is passivated and if during passivation container removes the Session Object.Then the instance after activation will useless as the Object is already removed by container.
Q1. Please let me know if I am correct

The second paragraph starts with "client invokes a session object " .
Q2. Does it mean " client obtaining a reference to a stateful session bean instance again " ?
 
Creator of Enthuware JWS+ V6
Posts: 3290
296
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

As far I understand,Instance is a reference to Object.


No, the instance is the object itself. The reference is a pointer to the instance. If the instance is removed by the container, the reference (pointer) is useless.

"client invokes a session object "


For this you can best explain it by accessing a website with a shopping cart, where you will put your products in while shopping. This shopping cart is implemented by a Stateful Session Bean. If, for whatever reason, you go away from your computer the server time-out might expire causing the shopping cart (e.g. Stateful Session Bean) to be emptied. When you return to your computer you are not aware that you shopping cart is not valid anymore so you just put another article in there (i.e. you invoke another business method on the Stateful Session Bean through the Servlet that had a reference to that bean. The reference in the Servlet doesn't point to the bean anymore). This will cause the application to signal you that your session was expired and that you have to start filling your cart up again.

Regards,
Frits
 
Mohit G Gupta
Ranch Hand
Posts: 634
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Frits,

As you said :

No, the instance is the object itself



If the above statement is true,then if a instance( or object) is in passivated state(see below) ,then How can Container may remove the session object(as it was passivated earlier ) ?

While the instance is in the passivated state, the container may remove the session object after
the expiration of a timeout specified by the Deployer. All object references and handles for the
session object become invalid.

 
Frits Walraven
Creator of Enthuware JWS+ V6
Posts: 3290
296
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

If the above statement is true,then if a instance( or object) is in passivated state(see below) ,then How can Container may remove the session object(as it was passivated earlier ) ?


A passivated Session Bean is put in some sort of secondary storage (in a serialized form) and mostly put there because it was not recently referenced. If the session timeout occurs, while passivated, the container will remove the Session bean from the secondary storage.

Regards,
Frits
 
Mohit G Gupta
Ranch Hand
Posts: 634
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,Understood now.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!