The answer to your EntityManager question is both yes and no :) The managed EntityManager instances from the Aries JPA container (the blueprint injected ones, not ones you create yourself) are safe to use concurrently as long as each thread has a different transaction context. We also inject a different instance into each injection site.
This means you are thread safe as long as you never have two threads with the same transaction context accessing the same EntityManager instance (in the same bean instance). This cannot happen if you have an active transaction, but is possible if there is no active transaction. My advice would be to only ever access a managed EntityManager from within a transaction context, then you can treat it as if it were thread safe. As for OSGi services, OSGi only offers two ways to provide a service. One is as a singleton, one is as a single instance per bundle that uses it. We did discuss the concept of a "stateless" scope for blueprint beans (much like a pooled stateless session bean in Java EE), but I don't think we ever had time to implement it. If you'd like to add it to the code as a contribution then please be our guest! Regards, Tim > Date: Mon, 20 Jun 2011 18:38:12 +0200 > From: [email protected] > To: [email protected] > Subject: Thread-Safety > > Is an EntityManager injected from the Aries JPA container thread-safe, > just like in Java EE? > > Going one level higher, is an OSGi service injected via Blueprint into a > web component thread-safe, like an EJB? > > I wouldn't think so, but does Aries offer some support for wrapping > services in a thread-local or pooling proxy, or some other best practice > for making services thread-safe? > > Best regards, > Harald
