aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes @Predestroy and timeout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "@Predestroy and timeout" Watch "@Predestroy and timeout" New topic
Author

@Predestroy and timeout

Mirko Bonasorte
Ranch Hand

Joined: May 14, 2007
Posts: 244
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


SCJP<br />SCWCD 1.4 Upgrade (Remember: me stupid)<br />SCWCD 1.4<br /><a href="http://jcp.org/aboutJava/communityprocess/final/jsr220/index.html" target="_blank" rel="nofollow">SCBCD 5.0</a><br /><a href="http://www.enthuware.com" target="_blank" rel="nofollow">SCBCD 5.0 mock exam</a> <br /> <br />SCEA 5 Part1: Preparing...
Sergio Tridente
Ranch Hand

Joined: Mar 22, 2007
Posts: 329

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?


SCJP 1.4 (88%) - SCJP 5.0 Upgrade (93%) - SCWCD 1.4 (97%) - SCBCD 5.0 (98%)
nitin pai
Ranch Hand

Joined: May 30, 2006
Posts: 185
@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

Joined: May 14, 2007
Posts: 244
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

Joined: Mar 22, 2007
Posts: 329

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

Joined: May 14, 2007
Posts: 244
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

Joined: Mar 22, 2007
Posts: 329

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

Joined: May 14, 2007
Posts: 244
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

Joined: Mar 22, 2007
Posts: 329

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.
Nikhil Jain
Ranch Hand

Joined: May 15, 2005
Posts: 385
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?


SCJP 1.4, SCWCD 1.4, SCBCD 1.5
Nikhil Jain
Ranch Hand

Joined: May 15, 2005
Posts: 385


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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: @Predestroy and timeout