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

When does the entity bean get released?

 
Author
Posts: 6055
8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I do a findByPrimaryKey() on an entity bean, I get a reference to a particular instance of the bean. As I understand it, this is blocking, such that no one else may access the bean.
When do I stop blocking? Is it only when the method which did the lookup exits, and the reference goes out of scope? Can I set the reference to null and release it earlier? Is this vendor specific, and if so, what do most vendors do?
--Mark
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The key here is to understand that the remote reference the client holds is not "permanently" attached to the bean instance. Three clients may be holding remote references to the same object on the server. Through instance pooling and concurrency management the container is required to manage such a scenario. In the finder scenario, after the ejbFind method completes, the instance remains in the pooled
state. The container may, but is not required to, activate the objects that were located by the
finder using the transition through the ejbActivate() method.
To answer your question, there is no blocking when a finder method returns. What is returned to the client is the identity of the entity bean that may potentially be pooled on the server and shared between clients.
Hope is is clear now as mud
 
Mark Herschberg
Author
Posts: 6055
8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, clear as mud is about where my understand is.
OK, so the finder really only returns the reference to the object (duh, this is how all EJB's work). So now I have three clients all with reference to the same object. Let's say the entity has some int field called quantity, and these three clients all modify that field by adding to it or subtracting from it. To make this concrete, let's say quantity starts with the value of 7.
Each client gets a reference to the entity bean at the start of some method. The server returns the references and continues on its way. The entity bean itself is undisturbed (it may be persisted or activated or whatever--who cares, it hasn't been "used" yet).
Eventually, one of the clients, client A, invokes some method to alter the quantity, say, adds 2. Now quantity = 9. Client A wants to alter it again, but before it does, client B invokes the same method on the bean, and adds 3, so now quantity = 12. When client A invokes it again, to add 4, it's adding 12 + 4 and we get the correct value of 16, right?
So the locking is only done when particular methods are invoked?
--Mark
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic