This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Originally posted by ShivPrakash Srivastava: Can a bean can be removed(Killed) in its passivated state may be due to timeout or any other reason
It depends on what do you mean by removed/killed. Are you refering to the invocation of the ejbRemove method? Or a transition from the passivated state to "does not exist" state.
If you recall from the life-cycle diagram of a stateful session bean or entity bean, when the bean is in passivated state, it can transit back to the "does not exist" state after a timeout. Also, ejbRemove method is not invoked at all.
But is time-out is the only way by which the bean bean transits to "does not exist state ".Even in its passivated state the bean is still referenced by the EJBObject,the only thing is it cannot be invoked(both for stateful as well as entity bean).Can we call ejbRemove() on a passivated bean?
Passivation is something limilar to serialization. Imagine the scenario that you are going through 3 books to pass SCBCD. After a while you thought that you are done with Book_1 and so the book is no more on your table but is sitting on the shelf.
Passivated bean is something like Book_1.
Unless and until you get the book to your table, you will not be able to do anything with the book.
Even to throw the book out of your room, you will first have to get it out of the shelf state and then act on it i.e. throw it out of the room.
HF states the reason why container does not call remove on passivated bean when the bean times out.
The reason given is, why should the container bother to activate the bean again just to call remove method. Better save the CPU cycles and put it out of the pool directly.
Thanks & Regards<br />Chetan
Joined: Mar 24, 2005
Thanks Chetan for your comments with a good example
Joined: Apr 02, 2004
Originally posted by ShivPrakash Srivastava: But is time-out is the only way by which the bean bean transits to "does not exist state ".
Nope, if the bean throws any system exception, it will transit to the "does not exist state" as well.