aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes ETS Question doubt 1 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 "ETS Question doubt 1" Watch "ETS Question doubt 1" New topic
Author

ETS Question doubt 1

Deepak Jain
Ranch Hand

Joined: Aug 05, 2006
Posts: 637
Source: ETS (Enthuware)

Which of the following methods can be used by a stateful session bean to clean up the resources that it has
acquired before its removal?

Options:
1) finalize -> Incorrect because session beans must not have finalize() according to Spec. However its a different story that when i had one, JBOSS did not bother to complain.
2) @Remove method -> This is the answer acc to ETS. And i dont agree with this because.
a) Invoking Remove method is client dependent, If the client does not invoke remove method, then the instance will be passivated and finally timedout. In this case
PreDestroy method will not be invoked. Hence PreDestroy() method is also not the correct place to release resources.
So how can this be correct answer ETS.
3) afterCompletion: This can be used only if sfsb is using CMT. However if used then the resources will have
to be acquired again before the start of next new transaction. Hence this is also not a reliable method. It never
works for BMT anyway. Since tje question does not metion of the type of transaction model, this option cannot be
chosen. Even if CMT was used and the resources acquired in NotSupported, Supports and Never business methods cannot
be released in afterCompletion, cause afterCompletion will not be invoked. Hence this option is ruled out.
4) unsetSessionContext: This method does not exists.

Hence i think there is no answer for this question for the options that are given.
ETS Answer and explanation:
Remember:
@Remove method

An ejb acquires resources in PostCreate and PostActivate callback methods and it releases the same resources
in Remove and PrePassivate methods.

If a bean is passivated and if the timeout occurs, the container does not call the Remove method.

I think the answer to this question is PrePassivate() and REMOVE method both together. Only PrePassivate() is
guaranteed to be invoked in all circumstances before a instance moves from methodReadyState and DoesNotExists.
However if the client invokes Remove method then PrePassivate() will also not be invoked.

Hence the correct answer is have resource removal code in Remove "AND" PrePassivate methods. Remember its AND
and NoT OR.
Is my understanding correct?


SCJP, SCWCD, SCBCD
Deepak Jain
Ranch Hand

Joined: Aug 05, 2006
Posts: 637
Experts/Ranchers, Please take time and reply.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ETS Question doubt 1
 
Similar Threads
Session Bean Contract LifeCycle Enthuware
EJB Spec violationg for session bean rules.
ETS Question doubts
Long Awaited - Answers to batches #2, #3, #11
Life cycle CallBacks for Enterprise beans