<p dir="ltr">Thats sort of what we are planning on doing. The rub is every library that interacts with JTA having to do this as well. Thats more what I think Scott was getting at.</p>
<p dir="ltr">For clarity your suggestion (method entry checks) is part of our solution. We will also do method exit checks. Ugh. Lot of work to handle something the TM is doing</p>
<div class="gmail_quote">On Feb 22, 2013 1:53 PM, "Jason Greene" <<a href="mailto:jason.greene@redhat.com">jason.greene@redhat.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I had a discussion with Steve about this. Not sure if you guys talked about my suggestion.<br>
<br>
My suggestion was to simply detect if afterCompletion is running on the thread that created it. If the threads match proceed normally. If, however, they do not match then DO NOTHING (well at first):)<br>
<br>
Then have the EntityManager, immediately before certain actions such as a flush, detect if the Transaction has been rolled back (using Transaction.getStatus()). If it has been rolled back then at that point of time trigger an exception to the calling application code, with a message that the "Transaction manager has decided to revert the transaction, either due to a timeout or a resource failure. Check your log for details".<br>
<br>
On Feb 22, 2013, at 8:45 AM, Scott Marlow <<a href="mailto:smarlow@redhat.com">smarlow@redhat.com</a>> wrote:<br>
<br>
> Related jira issues are HHH-7910 + AS7-6586. HHH-7910 has been around a<br>
> bit longer and contains comments about the current plan to address the<br>
> issue in Hibernate.<br>
><br>
> As mentioned in HHH-7910, the JTA specification allows<br>
> Sychronization.afterCompletion callbacks to occur in a different thread<br>
> than the application thread that is using the transaction (typically for<br>
> transaction timeout or when a transaction is propagated to a remote thread).<br>
><br>
> Since the JPA EntityManager is by design, not thread safe, invoking the<br>
> EntityManager.clear() or EntityManager.close() methods from a background<br>
> thread while the application thread may be in the middle of an<br>
> EntityManager invocation is not the best situation (IMO).<br>
><br>
> One improvement that we talked to the JBossTM/TS team about, is adding a<br>
> TM policy that arranges for the Synchronization.afterCompletion to<br>
> always run in the application thread (some of the IRC discussion is<br>
> attached to HHH-7910). The TM team doesn't think that they could do<br>
> that for both the TX timeout and tx propagating to a remote thread<br>
> (JBossTS) uses.<br>
><br>
> One alternative solution, might be to create a top level container level<br>
> queue that the background thread Synchronization.afterCompletion defers<br>
> processing to. As soon as the application thread returns control to the<br>
> top level, the queue is processed in FIFO order.<br>
><br>
> *Does AS have any other uses of Synchronization.afterCompletion or<br>
> Synchronization.beforeCompletion that expect to run in the application<br>
> thread*?<br>
><br>
> From the JPA specification about thread unsafety:<br>
><br>
> "<br>
> An entity manager must not be shared among multiple concurrently<br>
> executing threads, as the entity manager and persistence context are not<br>
> required to be threadsafe. Entity managers must only be accessed in a<br>
> single-threaded manner.<br>
> "<br>
> _______________________________________________<br>
> jboss-as7-dev mailing list<br>
> <a href="mailto:jboss-as7-dev@lists.jboss.org">jboss-as7-dev@lists.jboss.org</a><br>
> <a href="https://lists.jboss.org/mailman/listinfo/jboss-as7-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/jboss-as7-dev</a><br>
<br>
--<br>
Jason T. Greene<br>
JBoss AS Lead / EAP Platform Architect<br>
JBoss, a division of Red Hat<br>
<br>
<br>
_______________________________________________<br>
jboss-as7-dev mailing list<br>
<a href="mailto:jboss-as7-dev@lists.jboss.org">jboss-as7-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/jboss-as7-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/jboss-as7-dev</a><br>
</blockquote></div>