This week's giveaways are in the MongoDB and Jobs Discussion forums.
We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line!
See this thread and this one for details.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes When all @PreDestroy gets called? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Reply Bookmark "When all @PreDestroy gets called?" Watch "When all @PreDestroy gets called?" New topic
Author

When all @PreDestroy gets called?

Rajesh So
Ranch Hand

Joined: Oct 08, 2002
Posts: 111
Hi,

May I list down all the cases where @PreDestroy is guaranteed. Would be greatful if you can correct.

  • The Stateful Session Bean's method was called by a client and is complete. The Bean is idle for some time. It gets passivated and times out of passivation. The @PreDestroy is called.
  • The Stateful Session Bean's method is called and is complete. The @Remove method is called by client. The Bean calls Remove and then the @PreDestroy method.
  • The Stateful Session Bean was used by the Client. Suddenly a System Crash happens. Does the server bother to call the @PreDestroy, when the System itself is undergoing crash?


  • Regards,
    Rajesh
    Amandeep Singh
    Ranch Hand

    Joined: Jul 17, 2008
    Posts: 832
    in your 3rd case, it will not bother to call.


    SCJP 1.4, SCWCD 5, SCBCD 5, OCPJWSD 5,SCEA-1, Started Assignment Part 2
    My blog- http://rkydesigns.blogspot.com
    Treimin Clark
    Ranch Hand

    Joined: Nov 12, 2008
    Posts: 757
    Rajesh So wrote:
    The Bean is idle for some time. It gets passivated and times out of passivation. The @PreDestroy is called.


    As I know @PreDestroy is not called in this case. It is called, only if the bean is in activated (object) state. If it is in passivated state when timing out, the bean (passivated) will be destroyed without calling @PreDestroy method.
    Rajesh So
    Ranch Hand

    Joined: Oct 08, 2002
    Posts: 111
    Do you believe only in case 2 that @PreDestroy is called? Is @Remove, the only route to @PreDestroy?

  • The Stateful Session Bean's method is called and is complete. The @Remove method is called by client. The Bean calls Remove and then the @PreDestroy method.


  • Other than the cases I mentioned, is there any other way to reach @PreDestroy?
    Treimin Clark
    Ranch Hand

    Joined: Nov 12, 2008
    Posts: 757
    Rajesh So wrote:
    Other than the cases I mentioned, is there any other way to reach @PreDestroy?


    If the session (bean) is timed-out, while the bean is in active (non-passive) mode.

    Rajesh So
    Ranch Hand

    Joined: Oct 08, 2002
    Posts: 111
    If the session (bean) is timed-out, while the bean is in active (non-passive) mode

    May I know how to simulate this in Glassfish?

    Are all Routes to @PreDestroy are mentioned in this post? Have we left out anything?
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: When all @PreDestroy gets called?
     
    Similar Threads
    Some questions
    Stateful session bean calling @remove method from client
    Confusion in call back methods
    @Predestroy and timeout
    Confusion between PreDestroy and Remove annotation