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

ETS Question doubt 1

Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

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:
@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?
Deepak Jain
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Experts/Ranchers, Please take time and reply.
There's a city wid manhunt for this tiny ad:
a bit of art, as a gift, that will fit in a stocking
    Bookmark Topic Watch Topic
  • New Topic