Protomatter version: 1.1.8
Compile JDK: 1.3.1_09
Runtime JVM: 1.4.2
Database: DB2 7.2
OS: Windows XP
Attached is a JUnit test that sets up a pool with 3
connections and then queues 99 clients. This test
completes approx 50% of the time. The remaining time it
deadlocks. As you can see from the test itself, each
client takes and returns only one connection, so I
believe it is not a client code fault.
Tracing through the execution shows that the thread
with the lock on the DriverManager.getConnection()
goes into an indefinite wait but does not respond to
notification by the thread that returns the next
connection. Not sure how this happens; the
synchronization on the waiting thread and the waiting
list (in SimpleObjectPool) looks correct to me.
A short-term fix is to limit the wait of the thread (see
SimpleObjectPool.checkOut()):
Before:
synchronized (thread)
{
addToWaiters(thread);
thread.wait();
}
After:
synchronized (thread)
{
addToWaiters(thread);
thread.wait(100);
removeWaiter(thread);
}
The remove only matters if the notification failed. This
solves the deadlock in the test case, but is a kludge.
JUnit soak test