ConcurrentModificationException when using Persistence in two different threads

Description

When I create two EntityManagerFactories in two different threads, I get the stacktrace below. It looks like I'm determining the persistence provider implementations twice at the same time; the static set in the Persistence class is not thread safe; in particular findAllProviders() fails if it is called concurrently. In this case, the use of the persistence api in the two different threads is completely unrelated--they are using different persistence units, different dbs, etc. This seems like a use case that should be supported?

[java] java.util.ConcurrentModificationException
[java] at java.util.HashMap$HashIterator.nextEntry(HashMap.java:793)
[java] at java.util.HashMap$KeyIterator.next(HashMap.java:828)
[java] at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
[java] at com.darkcorner.minotaur.sa.redline.RedlineDatabaseControl.ensureRunning(RedlineDatabaseControl.java:101)
[java] at com.darkcorner.minotaur.sa.redline.RedlineService.restartService(RedlineService.java:316)
[java] at com.darkcorner.harmonice.ServiceHandler.callRestart(ServiceHandler.java:241)
[java] at com.darkcorner.harmonice.ServiceHandler.access$000(ServiceHandler.java:56)
[java] at com.darkcorner.harmonice.ServiceHandler$RestartTask.run(ServiceHandler.java:63)
[java] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
[java] at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
[java] at java.util.concurrent.FutureTask.run(FutureTask.java:138)
[java] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98)
[java] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:207)
[java] at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
[java] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
[java] at java.lang.Thread.run(Thread.java:619)

Environment

None

Activity

Show:
Brett Meyer
December 19, 2013, 10:31 PM

Note: In an attempt to clean up the HHH JIRA, we will be rejecting any ticket that sits in the "Awaiting Test Case" state for 2-3 months with no response. So, if this issue is critical to you, please attach a reproducing test case ASAP. Thanks!

Kenneth Flynn
December 23, 2013, 12:18 AM

Because of the nature of the exception (concurrency), it's probably going to be difficult to produce a relevant test case; I've worked around this with some additional concurrency guards. My hope was that the specific stack trace would highlight the problem on inspection.

Kenneth Flynn
December 23, 2013, 12:19 AM

Version on this is a long time ago--I'm not sure that the issue is still relevant. Might be worth looking at, but I suspect this ticket is OBE.

Brett Meyer
December 23, 2013, 1:25 AM

Moving this over to JPA – looks like your stack is an issue with our javax.persistence.Persistence impl.

Brett Meyer
December 23, 2013, 1:27 AM

In looking at the current impl in hibernate-jpa-2.1-api-1.0.0.Final, it looks like that static Set is no longer used. So, closing this (unless someone is able to still reproduce somehow). , thanks for the response!

Assignee

Unassigned

Reporter

Kenneth Flynn

Labels

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Suitable for new contributors

None

Pull Request

None

backportDecision

None

backportReEvaluate

None

Priority

Major
Configure