users@ejb-spec.java.net

[ejb-spec users] Section 16.15.2 question: is SessionContext obligated to be threadsafe?

From: Laird Nelson <ljnelson_at_gmail.com>
Date: Mon, 20 Aug 2012 11:22:42 -0700

Section 16.15.2 of the EJB 3.1 specification states in its entirety:

The Container Provider is responsible for providing an appropriate
> EJBContext object to the referencing component. The object returned must
> be of the appropriate specific type for the bean requesting injection or
> performing the lookup—that is, the container provider must return an
> instance of the SessionContext interface to referencing session beans and
> an instance of the MessageDrivenContext interface to message-driven beans.


Must this EJBContext object be safe for use by multiple threads?

In a stateless session bean that injects a SessionContext, the object
*must*obviously be thread safe, since a stateless session bean is
prohibited from
using synchronization primitives, and hence would be unable to use the
synchronized keyword to control access to this object.

But what about in a singleton session bean with bean-managed concurrency?
 Suppose such a bean has a SessionContext injected into it. Must that bean
synchronize access to the SessionContext? Or is the
SessionContextguaranteed by some other part of the specification to be
thread safe?

(Related StackOverflow question here:
http://stackoverflow.com/questions/12028144/is-a-javax-ejb-sessioncontext-injected-into-a-bean-managed-concurrency-singleton
)

(Related GlassFish forum post here:
http://www.java.net/forum/topic/glassfish/glassfish/sessioncontext-inherently-thread-safe-even-bmc-singleton
)

(Background:
http://ljnelson.posterous.com/java-ee-compatible-abstractexecutorservice-im-6803
)

Best,
Laird

-- 
http://about.me/lairdnelson