I came across this blog below, concerning Servlets and injecting EJBs into them. The author is writing from a standards point-of-view.
http://tamanmohamed.blogspot.ie/2012/03/jpa-why-we-need-to-specifies-type-level.html http://tamanmohamed.blogspot.ie/2012/03/jpa-thread-safety-when-injecting.html
"injecting EJB 3 stateful beans into servlet instance fields is not thread-safe. Along the same line, injecting EntityManager with @PersistenceContext into servlet instance variables is not thread-safe, either. EntityManager is just not designed to be thread-safe."
Anyhow, I am starting to get worried about the code I'm writing with a colleague in the Glassfish-3.1.2 implementation. See below. I thought it was similar to code I've seen in Duke tutoring tutorial so it should be o.k. (where FaceServlets call a stateless Request bean with @PersistnceContext EntityManager.)
However I guess I'm assuming the container-managed EntityManager is capable of coping with lots of concurrent calls of a stateless bean called by many instances of servlets.
Is this a correct assumption for Glassfish-3.1.2 with an Oracle database ? It seems to work fine so far, but maybe it won't under heavy loads.
thanks in advance for any insights. Sorry I'm such a newby to this. Fiona
Servlet
{
@EJB
private StatelessbeanBlah
:
}
@Stateless
StatelessBeanBlah
{
@PersistenceContext(unitname = "...")
private EntityManager em;