Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Where an entity bean should acquire additional resources ?

 
author
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
according to EJB 1.1 specifications there are two "potential"
methods where resource can be acquired in an Entity bean:

public void ejbActivate();
"The ejbActivate() method gives the entity bean instance the chance to acquire additional resources that it needs while it is in the
ready state."

public void setEntityContext(EntityContext ic);
"The instance can take advantage of the setEntityContext() method to allocate any resources that are to be held by the instance for its lifetime. Such resources cannot be specific to an entity object identity because the instance might be reused during its lifetime to serve
multiple entity object identities."

It seems that the only difference is that setEntityContext is called prior (when the bean is still in the pool) to ejbActivate.

But should you have the question in the Subject on the quiz-day what should you vote for ?

a) ejbActivate
b) setEntityContext

Thanks a lot
Francesco
 
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Francesco Marchioni:
But should you have the question in the Subject on the quiz-day what should you vote for ?
a) ejbActivate
b) setEntityContext



setEntityContext - because ejbActivate will not be called when the bean moves from "pooled" to "ready" through the ejbCreate/ejbPostCreate call. Take a look at the "Life cycle of an entity bean instance" diagram.

Under different circumstances (where you need to shorten the holding time) you may want to call an acquisition helper method from both ejbCreate/ejbPostCreate and ejbActivate; then call a release helper method from ejbPassivate and ejbRemove. However under these circumstances you would probably call both helper methods from the business methods that use the resources - unless resource acquisition and release are extemely expensive and/or time consuming.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic