• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
  • salvin francis
  • Frits Walraven
  • Piet Souris

doubt : stateless bean dependency injection

Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I came across a note where it says obtaining two instances of a stateless bean via dependency injection will always be equal.

I tested it and it is true.

@EJB MySLBeanLocal mySLBean1;
@EJB MySLBeanLocal mySLBean2;

mySLBean1.equals(mySLBean2) always returns true.

But I am not sure what is the reason behind it? Isn't that while invoking stateless bean like that it is always upto the container to return which object from pool?

Any clarification will be really helpful.
Ranch Hand
Posts: 10192
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per the EJB specification, the container always maintains equal instances of the Stateless Session beans in its pool. There is no state associated with Stateless session beans. Can you now make it out?
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

In the ejb 3.0 specification on page 47 ( Stateless Session Beans) you can find

The equals method always returns true when used to compare references to the same business interface type of the same session bean. Session bean references to either different business interface types or different session beans will not be equal.

I hope that this helps, in the same document - somewhere upper - is they describe the equals for statefull.

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic