Post by j***@yahoo.comHi All,
Here is part of the program. I just want to simulate the deadlock
environment in order to test out the deadlock handling part.
do {
errorCode = 0;
try {
GenUserProfileDAO.resetLogin(userId);
} catch (SQLException sqle) {
errorCode = sqle.getErrorCode();
retry++;
try {
Thread.sleep(getRandom()*1000);
} catch (InterruptedException ie) {
log.error("Thread sleeps failed", ie);
}
}
}while (errorCode == -911 && retry < SystemConfig.LOGOUT_RETRY);
I use the method u suggest.
1) set locktimeout = 30
2) db2 +c lock table genuserprofile in exclusive mode
I didn't get the deadlock exception but instead this is the error I got...
ThreadMonitor W WSVR0605W: Thread "WebContainer : 0" (0000001c) has been
active for 608062 milliseconds and may be hung. There is/are 1 thread(s)
in total in the server that may be hung.
First, the method I suggested above will not yield a deadlock, but it will
yield a locktimeout. Both are -911, but a deadlock is reason code 2 and
locktimeout is reason code 68.
It looks like you are getting a warning error from Websphere, which is your
connection pooling software.
Keep in mind that until you release the table lock in step 2 above, your
java program will keep doing the retry logic after the 30 second locktimeout
period is over and your program receives its first -911 (basically in a
loop), but nothing will change since it is still locked and eventually
Websphere will issue the WSVR0605W above. So my guess is that your retry
logic is working, if that is really what you want to do. You probably need
some kind of "give up" logic if the locking problem is not resolved within a
reasonable time before you get whacked by Websphere.
Also keep in mind that DB2 automatically checks for true deadlocks (not
locktimeouts) every 10 seconds (by default) and solves the problem by
cancelling one the applications (the victim) to let the other one through.