I've found out what's the problem with failing test, this finally block should be like this:

finally {
         em2.getTransaction().commit();
         em2.close();
         latch.countDown();	// signal that tx2 is committed
}

I think, we should close em2 before we send the signal, because sometimes em2 appears to be opened after the test completion -> releaseUnclosedEntityManagers() is invoked, but in the meantime em2 is closed in the finally block in another thread.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira