views:

13

answers:

1

Hello guys,

I have read this thread: J2EE/EJB + service locator: is it safe to cache EJB Home lookup result ? I use the same approach, i.e. I obtain EJB home object for my entity bean and cache it in a servlet.

My question is: is it safe to share this object between multiple threads?

From EJB 2.1 spec I found only that concurrent calls to entity beans [via local / remote interface] are serialized internally by the container. However, the spec doesn't expand on concurrent calls to home objects.

Does anybody have an idea? The reference to the exact place in a spec / doc would be very welcome as well.

A: 

EJBHome and EJBObject are equally thread safe. The container takes all responsibility for the thread safety of those implementations.

Very often an app server will create one instance of a bean's EJBHome or EJBLocalHome and tie it directly into JNDI for all the application to share. I bet if you looked up your EJBLocalHome twice from inside a servlet and did an == compare on the two, there'd be good odds that it was the exact same instance.

David Blevins