• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Where an entity bean should acquire additional resources ?

 
Francesco Marchioni
author
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • 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
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic