Another potential problem with a different thread being used for each application invocation, is what happens if the tx completes on the invocation but doesn't call any EntityManager methods.  When the afterCompletion() is invoked in the application thread, I think that the saved thread-id will be for a different thread, so we will defer clearing the session until further work occurs with that particular EntityManager (even though we are actually in an application thread). 

Should we discuss this situation with the JPA EG?  My specific question is how is the thread unsafe EntityManager supposed to be cleared from a JTA afterCompletion that can come from any thread (as per xopen spec section 3.6 "Transaction Timeout" that is referred to from JTA spec).