Debugging Hibernate/Ehcache deadlock?

Answering my own question just in case if someone else slips on this and the post in Ehcache forums will disappear.

Answering my own question just in case if someone else slips on this and the post in Ehcache forums will disappear. The reason: The reason for the deadlock was coming from the same thread, where an attempt to locate the object in the cache was done. In one of the bottom parts of the stack, Ehcache was doing readLock().lock() and writeLock().lock() on the same lock object.

This is obviously a no-no. Why did this happen? This happened because cache was loading another object as a side effect (another big no-no) and both objects ended in the same memory segment (and hence shared the same ReentrantLock).

Nt: I use the same cache region as I did not want to specify capacities for hundreds of different entity types. Why did this happen? Inadvertent loading on cache key lookup was happening because of my The object (which was being looked up) had a composite key, referring to another object.

Parts of that composite key have been used in the equals method and was causing that load. As a coincidence, loaded object was also attempted to be placed in the same cache segment - and causing a deadlock. Lessons learned Be extra careful with your If you have a composite key, never use I think many people do not realize this only because they place different types of objects into different cache regions, but inadvertent loads are nevertheless evil.

All credits go to Alex from Terracotta forums for helping me to find this out.

You could use JProfiler (there's a fully functional evaluation version) to look at the current locking graph. It supports java.util. Concurrent locks and will tell you who has the lock and where it was acquired.

With that information it will be easier to analyze the problem. Disclaimer: My company develops JProfiler.

Thanks kingo, but in this case the debugger is much more appropriate tool than the profiler. I found out that Ehcache acquires the read lock first and then attempts to acquire the write lock. The question is why does the bernate orchestrate it this way... – mindas Oct 19 at 10:54.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions