Deadlock, if two threads try to close an entity manager



we get into a deadlock, if two threads  try to close an entity manager.

The first thread try to close the entity manager factory which close all opened entity managers.

The second thread is triggered by an event and try to close the entity manager after a database access.

Both threads keep in the close method of the entity manager and never leave the close.

Why one of the threads cannot leave the close?


Could you please send a thread dump that shows the deadlock?

ObjectDB Support

We have only a profiling which can open with the VisualVM from JDK.

You can see this behavior in the attached profiling in the treads 'Java FX Application Thread' and 'ModalContext'.




Unfortunately we need thread dumps in order to see a deadlock.

The profiling info does not include lock and deadlock information.


ObjectDB Support

Unfortunately we have not a dump and the issue occurs only sometimes.


Could you please take the a thread dump next time that this deadlock happens?

ObjectDB Support

Yes, we try this next time.



we have a thread dump.


Thank you for the thrad dump, it clearly shows a deadlock when:

  1. One thread is closing an EntityManager.
  2. Another thread is closing the EntityManagerFactory that owns that EntityManager.

Both threads require locks on both the EntityManager and the EntityManagerFactory but in a different order, so that can cause a deadlock.

Now that the issue is clear we hope to be able to fix it as soon as possible.

ObjectDB Support

Build 2.8.1_01 should solve the issue.

It is avilable now for download and soon also on Maven.

Thank you for this report.

ObjectDB Support