One of the most interesting problems I worked on was a deadlock between the JVM and the Database.
This blog post is a case-study of some sorts.
I will talk about the symptoms we saw, how we analysed the problem, and the solution.
A J2EE web application running on Tomcat
Remind me one more time – what is a deadlock ?
Deadlock happens when two (or more ) processes have acquired a lock and are now waiting for the other process to release its lock first- before it can proceed further. Since each process would wait for the other process to complete first- it becomes a deadlock- i.e there is no way out unless someone intervenes.Oracle will immediately detect and break the deadlock by killing one of the process, and I believe JVM also has a similar recovery process.
So what so special about this deadlock ?
When you have a deadlock across the two systems i.e one lock exists in the JVM and another lock in Oracle, it is impossible for either system to detect it- because they simply do not know about the existence of the other lock . Each system considers it as a uni-directional lock. Uni-directional locks aren’t a problem(generally). Deadlocks are . In our case, the lock in the JVM was by the usage of a synchronized block and the lock in Oracle was because of update on one table and a pending commit. Both these locks would exist for ever. Why? Read on…