For each dependency injection of a stateless session bean in another component, a new instance of the injected bean is created.
On this piece of specs you would say: a new instance is not created everytime
But on the other hand in chapter 16.2.1 Sharing of Environment Entries the following is stated:3.4.7.2 Stateless Session Beans
All business object references of the same interface type for the same stateless session bean have the same object identity, which is assigned by the container. All references to the no-interface view of the same stateless session bean have the same object identity.
For example,
@EJB Cart cart1;
@EJB Cart cart2;
...
if (cart1.equals(cart1)) { // this test must return true
...
}
...
if (cart1.equals(cart2)) { // this test must also return true
...
}
andEach injection of an object corresponds to a JNDI lookup.
On this part of the specs you would say: a new instance is created everytimeIn general, lookups of objects in the JNDI java: namespace are required to return a new instance of the requested object every time. Exceptions are allowed for the following:
•The container knows the object is immutable (for example, objects of type java.lang.String), or knows that the application can’t change the state of the object.
•The object is defined to be a singleton, such that only one instance of the object may exist in the JVM.
•The name used for the lookup is defined to return an instance of the object that might be shared. The name java:comp/ORB is such a name.
The only way I can combine the two pieces of specification is that for a Stateless Session bean the rule applies
"The container knows that the application can’t change the state of the object."
What do you think?
Regards,
Frits