This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Questions on Life Cycle of a Stateful Session Bean Instance

 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE 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 " ?
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2535
113
Android Chrome Eclipse IDE
  • 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
Chrome Eclipse IDE 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
Saloon Keeper
Pie
Posts: 2535
113
Android Chrome Eclipse IDE
  • 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
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,Understood now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic