Wednesday, June 13, 2007

Timed Deadlock

What is Timed Deadlock?:Timed deadlock is a deadlock where the thread t1 holds the lock l1 and wants to acquire a resource (for example a connection from the connection pool) when there are no resources and waits (sleeps) for a resource(s) to be available. In the mean time the thread t2 which has a resource but needs lock l1 to complete its task. The following figure illustrates timed deadlock.



Figure-1: Timed Deadlock

Example: The timed deadlock can be found in JBoss 2.4.x, please refer to the Reported Bug. The situation is caused when multiple to users (n > 20) are trying to access a portal. The connection pool size is set to 20 and the cache for portal meta data is set to expire every 2 minutes. When there are no connections in the connection pool, the requesting thread will be blocked for 30 secs (default).

The attached thread dump (from the reported bug) indicates that one thread holds a lock and ends up sleeping when trying to acquire a connection from the pool. All the other threads wait for the above lock to be release to finish their work. I am not sure if the other threads are holding connections or connections are not returned to the pool (connection leak).There could be multiple problems in JBoss portal contributing to the timed deadlock.

Conclusion: One thing is for sure that threads shouldn't hold a lock and interact with pools, especially the pools that provide waiting(sleep) option.

0 comments: