views:

151

answers:

1

We have a stateless EJB that is behind a webservices (EJB3), this EJB also loads a EntityManager that is passed in calls that it makes. With that I have a question.

Do simultaneous call to the webservice use the same EJB or is there different instances? I ask this especially concerning the use of the EntityManager, which is injected.

Thanks

+3  A: 

Is up to the Application server to use the same or different. You may think as if they were different.

Now, if you're injecting it I assume you have it declared as an instance variable, this is a very bad idea for an stateless EJB, because well. It should not have state.

Instead of inject the EntityManager, let the app server do its work, and you just take it from the context. Each method call from a stateless belongs to a transaction and won't interfere with others calls.

In summary: Assume they are different instances, and don't inject your self those kind of objects. Take them from the context where the app server is responsible to leave them.

I hope I've understand properly your question.

OscarRyz