I have a @Singleton
session bean. The bean is annotated with @ConcurrencyManagement
(
ConcurrencyManagementType.BEAN
)
.
It has a SessionContext
injected into it via the @Resource
annotation.
Is this SessionContext
inherently threadsafe (since it is a container-produced object that is also used in non-bean-managed-concurrency situations), or does my bean have to synchronize on a lock to access and manipulate it? Section 16.15.2 of the EJB 3.1 specification makes no mention of the thread safety of injected EJBContext
objects.
From a posting by Marina Vatkina on the users@ejb-spec.java.net
mailing list:
EJBContext
in non-singleton beans is accessed only by a single thread, so it doesn't need to be thread safe. If we use the following text in the section 4.8.5 Singleton Session Bean Concurrency, it makes it a developer responsibility to make sure the context is thread safe, if more than one thread can access that singleton instance at the same time:"It is legal to store Java EE objects that do not support concurrent access (e.g. references to Java Persistence entity managers or stateful session beans) within the singleton session bean instance state. However, it is the responsibility of the Bean Provider to ensure such objects are not accessed by more than one thread at a time."