• 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

Stateless EJBs

 
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, when I lookup a stateless bean for my java client to use, I have code that looks like this:



If I need to use another that stateless bean again in another method or at a later time, do I need to lookup the bean again? Or can I just save the reference to it (I understand it may not be the same exact instance)? I'm concerned that if the bean gets removed from the container the reference will become invalid.

Thanks,
Jeff
 
Ranch Hand
Posts: 2108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can save the reference and use it as long as you need.

It is transparent to your code on whether the container will use the same or a different instance; but the container is responsible that an instance be given to you when you need it, assuming an instance is available in the pool.
 
Jeff Storey
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jesus!

In stateful beans, I do need to worry about a bean remove/timeout, correct? If a stateful bean times out, the reference becomes invalid, correct?

Thanks again,
Jeff
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Typically, the bean instance will only be destroyed if it throws a system exception or if the EJB container decides to reduce the number of instances in the pool. If a client calls a remove method (which invalidates the stub), the instance will be back in the pool.

So, you may not want to save the stub reference, but you can cache the reference to the home object from the JNDI lookup. Note that this is not guaranteed to always work, I am thinking of where you have a clustered environment.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic