3

We use hibernate 4.3.8.Final, Spring4 and Java7.

A few times a day we have an issue that a few threads just hangs forever in HashMap.getEntry(), see StackTrace from ThreadDump

"catalina77" daemon prio=10 tid=0x00007fa600086800 nid=0x28b7 runnable [0x00007fa5cc6c1000]
   java.lang.Thread.State: RUNNABLE
        at java.util.HashMap.getEntry(HashMap.java:465)
        at java.util.HashMap.get(HashMap.java:417)
        at org.hibernate.engine.internal.StatefulPersistenceContext.getEntity(StatefulPersistenceContext.java:393)
        at         ...

This can only happen because the underlying HashMap is used by two different Threads. As HashMap is not thread-safe the method loops forever because of e = e.next in HashMap Line 465

I am pretty sure that we have two Threads which use the same Hibernate Session.

Janning Vygen
  • 8,877
  • 9
  • 71
  • 102

2 Answers2

2

We didn't use the Hibernate Session explicitly in two threads but we had a custom Cache where we did store some persistable Domain Objects instead of converting them to Data Objects before.

The next thread is picking up these Objects. The hibernate session is stored a long with the domain object and so you get the sessions mangled somehow.

So if you run in this problem, check if you save some domain objects elsewhere in memory and access them in a different thread.

Janning Vygen
  • 8,877
  • 9
  • 71
  • 102
0

It looks like you are right. (similar issue: Infinite loop in java.util.HashMap)

Hibernate session is not thread safe. You shouldn't access it from multiple threads.

Community
  • 1
  • 1
Michal
  • 970
  • 7
  • 11