File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes does ejbRemove() ever called on stateful bean? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "does ejbRemove() ever called on stateful bean?" Watch "does ejbRemove() ever called on stateful bean?" New topic
Author

does ejbRemove() ever called on stateful bean?

Prashant Neginahal
Ranch Hand

Joined: Sep 14, 2002
Posts: 77
Hi ,

There are two events happen from container when client doesnt make any calls.

1) The first event is for short time, the conatainer will call ejbPassivate() method.
2) Second event is for long time, the container will call ejbRemove() method.

If my understanding is correct, short time reaches first while waiting for call and always container should call ejbpassivate() method. So, ejbRemove()method should never be called.

--Prashant


Thanks, <br />Prashant<br />SCJP, SCBCD
Sanju Thomas
Ranch Hand

Joined: Dec 29, 2004
Posts: 243
Yea, ejbRemove() will be called by the container on bean instance when the client invoke remove() method in the ejbObject of the stateful session bean. This will be called only once in the life cycle of a stateful session bean.
Arun
Ranch Hand

Joined: Oct 03, 2003
Posts: 40
The difference between the two calls is not about time. ejbPassivate() is called by the container only when it is running short on resources(memory). If the server is not low on resources it will not bother to passivate a bean even though the bean has been around for a while.
As for the ejbRemove() method, it gets called by the container when a bean has timed out. Timeout is not about how long the bean has been in the 'method ready' state, it is about how long the bean has been left idle. A bean could time out when the bean is in the 'method ready' state or when it has been passivated. If it is in the passivated state, then it gets removed without getting re activated.

Hope this helps.. You may want to refer to pg184 - 185 of HFEJB for more info.
Cheers !
[ April 27, 2005: Message edited by: linoops ]
Kris Reid
Ranch Hand

Joined: Jan 05, 2005
Posts: 247
just to be clear when the bean times out, the container will call ejbRemove if the bean is in the method ready state but NOT if it is passivated.

ejbPassivate will usually be identical to ejbRemove
as they both release resources
Mudi Appu
Ranch Hand

Joined: Apr 06, 2005
Posts: 44
Though both ejbPassivate and ejbRemove are releasing resources they are not same by any means. When passivating the EJB container store/ persists the state of EJB and release resources. But removing is just like assign null into the reference. Meaning of removing passive EJB is removing the stored state of the EJB from the storage.
Hope this helps


SCJP 2
Prashant Neginahal
Ranch Hand

Joined: Sep 14, 2002
Posts: 77
thanks guys.

--Prashant
Arun
Ranch Hand

Joined: Oct 03, 2003
Posts: 40
A followup question to Kris's post. Since ejbRemove is not called if the bean has been passivated, how can i make sure that something always happens before a bean dies ???

Also, what is typically done in the ejbRemove method?? (Haven't used ejb's much, so real world examples of what you do in the ejbRemove will help).

Regards.
sawan parihar
Ranch Hand

Joined: Aug 24, 2004
Posts: 250
Also, what is typically done in the ejbRemove method?? (Haven't used ejb's much, so real world examples of what you do in the ejbRemove will help).

Most of the times in real world scenarios you will find these methods empty. .


Since ejbRemove is not called if the bean has been passivated, how can i make sure that something always happens before a bean dies

Put the code in both the ejbRemove and ejbPassivate. This will make sure that whenever the bean dies your code will be executed.

Hope that helps.


Sawan<br />SCJP,SCWCD,SCBCD<br /> <br />Every exit is an entry somewhere.
Purvesh Vora
Ranch Hand

Joined: Dec 10, 2003
Posts: 47
If the Bean is in Passive state on the server and client calls remove() then how will it behave? Will it activate the bean first and then call ejbRemove().


Regards,<br />Purvesh<br />SCJP, SCBCD, IBM Exam #486
Prashant Neginahal
Ranch Hand

Joined: Sep 14, 2002
Posts: 77
This is really good question. One thing is sure that Container will not activate it for the sake of removing it and it also not a business method to activate it.
Purvesh Vora
Ranch Hand

Joined: Dec 10, 2003
Posts: 47
Yes Prashant. Its meaningless to activate the bean just for removing it. But what is there in EJB Specs for such scenario?
Experts please provide your views.
Thanks.
sawan parihar
Ranch Hand

Joined: Aug 24, 2004
Posts: 250
Hi,
It depends upon the bean type. If we talk about the stateful bean and the client calls remove when the bean is in passivate stage then ejbRemove won;t be called.

On the other hand if its an entity bean bean and the client call the remove then the container will first Activate the bean just it case the bean is having any cascade delete.

Cheers.
Purvesh Vora
Ranch Hand

Joined: Dec 10, 2003
Posts: 47
Thanks Sawan.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: does ejbRemove() ever called on stateful bean?
 
Similar Threads
Shridar Ramas's Test
Answers to Mock Questions
ejbRemove and ejbPassivate
releasing resources
Some basic doubts on session beans...