• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

does ejbRemove() ever called on stateful bean?

 
Prashant Neginahal
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sanju Thomas
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Prashant Neginahal
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks guys.

--Prashant
 
Arun
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Purvesh Vora
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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().
 
Prashant Neginahal
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sawan.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic