• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

@Predestroy and timeout

 
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Greetings,
I have a doubt about Predestroy lifecycle callback interceptor and timeout for Stateful Session Bean: at page 245, paragraph "Transitioning out of Method-Ready state", O'Reilly's "Enterprise JavaBeans 3.0, fifth Edition" says:
"When a timeout occurs in the Method-Ready state, the container, but is not required to, call any @PreDestroy callback methods".
But at paragraph 4.4.3 of the specifications, you can read that:
"The following scenarios result in Predestroy lifecycle callback interceptor method(s) not being called for an instance:
1. A crash of EJB container
2. A system exception thrown from the instance's method to the container
3. A timeout of client inactivity while the instance is in the passive state. [...]"

So, during the Method-Ready state, is the PreDestroy method invoked or not?
Is it a mistake from my book?

Thanks in advances
 
Ranch Hand
Posts: 329
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mirko,

I am not able to see the contradiction.

The book's paragraph you quoted reads: "When a timeout occurs in the Method-Ready state, the container may, but is not required to, call any @PreDestroy callback methods". You forgot to transcript the word "may" which is crucial in this case: it may do it, but it is not required to.

What the specs say is that under some circumstances (EJB container crash, system exception thrown inside the instance's method or passivated instance timeout) Predestroy lifecycle callback interceptor method(s) are not called. But in all other cases (not passivated timed-out instances that do not throw a system exception) they are.

What do you think? Am I on the right track?
 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@PreDestroy as the name suggests is called when the container wants to get rid of the instance and wants to notify the bean that it is doing so.

In case of your question I presume that you want to know whether PreDestroy can be called in the method ready state or not. The answer is yes, It can.

In the case of a stateless session bean -
- if the processing has got completed and it is no longer required.

If its a stateful session bean then -
@PreDestroy happens as soon as the @Remove method gets completed.
 
Mirko Bonasorte
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,
thanks for the answer.
Well, what is not clear to me is:
If a stateful session bean in method-ready state timeouts, MAY or MUST the container invoke @Predestroy ?
O'Reilly book says it MAY, but the specs:
1. Reports it MUST, if you look at the stateful session bean state diagram
2. Says that the @Predestroy is not called in the above scenarios (see the original post)

Thanks in advances
 
Sergio Tridente
Ranch Hand
Posts: 329
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If a stateful session bean instance in the method ready state times out, the container will NORMALLY call @PreDestroy unless that instance has already been passivated in which case calling the @PreDestroy method is optional.

On the other hand, the exceptions you are referring to (EJB container crash, system exception from the instance's method, timeout of client inactivity while in passivated state) have to do with Predestroy lifecycle callback interceptors and not with calling the @PreDestroy method itself.
 
Mirko Bonasorte
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply, Sergio.

I perfectly agree with all you say. But, at this point, I should consider an error from my O'Reilly book the following:
"When a timeout occurs in the Method-Ready state, the container, but is not required to, call any @PreDestroy callback methods".
 
Sergio Tridente
Ranch Hand
Posts: 329
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see it as an error: both statements are talking about two different things:

- First one talks about a session bean's @PreDestroy lifecycle callback
- The second one about PreDestroy lifecycle callback interceptors methods

Please, note the emphasis on the word "interceptor". It is not the same: one is talking about a session bean's lifecycle callback and the other one about interceptors on that session bean's lifecycle callback. Two different objects: session bean vs interceptor.
[ June 27, 2008: Message edited by: Sergio Tridente ]
 
Mirko Bonasorte
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are right!
Thanks!

I thought @PreDestroy callback method and @Predestroy callback interceptor method had the same behaviour.

Uff, I'll never clear this damned exam.
Please, do you know other differences about these two callbacks?

Thanks a lot!
 
Sergio Tridente
Ranch Hand
Posts: 329
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, not that I am aware.

The 'only' visible difference that I am aware is:

- Session's beans @PreDestroy callback methods may be called if the bean's instance is in passivated state.
- PreDestroy lifecycle callback interceptors' methods will not be called when the instance is in passivated state.
 
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why is @PreDestroy not called when System Exception. I tried this, but in my case, it called @PreDestroy method. But the spec says that it does not call. If it does not call, where do we write the clean up code?
 
Nikhil Jain
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


The executePersistence method throws System Exception. As per spec 12.4.2
Predestroy call back should not have been closed. But in my case, it calls it. Am I reading the SPEC wrong?
reply
    Bookmark Topic Watch Topic
  • New Topic