wood burning stoves 2.0*
The moose likes Architect Certification (SCEA/OCMJEA) and the fly likes Confusion between PreDestroy  and Remove annotation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Bookmark "Confusion between PreDestroy  and Remove annotation" Watch "Confusion between PreDestroy  and Remove annotation" New topic
Author

Confusion between PreDestroy and Remove annotation

Gowher Naik
Ranch Hand

Joined: Feb 07, 2005
Posts: 643
Hi
I am able to find difference between PreDestroy and Remove callback annotation.
What i know that Remove annotation is used to tell container to remove statefull bean.The PreDestroy annotation is called after Remove annotation.

Why we need PreDestroy when there is Remove anotation?
We can do same thing in Remove annotation what we can do in PreDestroy annotation.

When bean is removed then how container call PreDestroy on bean which has been already removed?
Steven Young
Ranch Hand

Joined: Apr 11, 2007
Posts: 36
Hi,

The @PreDestroy annotation, along with the @PostConstruct is a standard lifecycle callback method for all session beans. This includes Stateful and Stateless session beans.

The @Remove annotation is only available to business methods of Stateful session beans so that the container knows when the client has finished the stateful conversation. The container can then destroy the stateful session bean and reclaim system resource. Think of the @Remove callback method as a "marker" so the container knows you have finished with the bean. The container will not destory the bean straight after it completes the @Remove method, it will still run the @PreDestroy callback. How long the stateful bean hangs around before the @PreDestroy method is actually called is up to the EJB Container vendor.

So, although it appears that the 2 callback methods do the same thing, the @PreDestroy callback method is standard for all session beans (stateful or stateless) and should be used specifically to close and release any resources such as JDBC connections.
 
Don't get me started about those stupid light bulbs.
 
subject: Confusion between PreDestroy and Remove annotation
 
Similar Threads
Doubt in SessionBean contract(ejb 3.0 core)
@PreDestroy annotation
Confusion in call back methods
Invoking remove() methods from Home & Remote interfaces
@Predestroy and timeout