• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

Confusion between PreDestroy and Remove annotation

 
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
I'm so happy! And I wish to make this tiny ad happy too:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic