[jboss-user] [EJB 3.0] - Re: EntityManagers and DAOs

ALRubinger do-not-reply at jboss.com
Thu Nov 9 13:59:04 EST 2006


A couple of years ago my company had an EJB training session w/ Bill.  We had expressed concern over our "polluted" method signatures and passing the same variables all over the place.

He suggested the use of ThreadLocal, citing that it will have the same scope as any one execution context (or transaction).

So, the following holds true:

* A session bean call will execute in one thread
* Watch out for thread pooling

...if you set stuff in a ThreadLocal, ensure that its removed if the Thread has been obtained from a Thread pool.  Otherwise, nightmares.

For instance, I've set web-tier stuff in ThreadLocal to be easily obtained from other layers.  But Tomcat uses a thread pool, so after my request had executed, I had to ensure that a Filter ran at the end of my FilterChain to clean up anything I placed in the ThreadLocal.

Or in your case...if you don't want to put any JPA stuff in your DAO APIs...why not just pass the EM into the DAOImpl Constructor?

S,
ALR

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3984631#3984631

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3984631



More information about the jboss-user mailing list