提交 9482daac authored 作者: Thomas Mueller's avatar Thomas Mueller

Avoid deadlocks

上级 ee6b0804
......@@ -251,20 +251,26 @@ public abstract class Command implements CommandInterface {
if (e.getErrorCode() != ErrorCode.CONCURRENT_UPDATE_1) {
throw e;
}
long now = System.currentTimeMillis();
long now = System.nanoTime() / 1000000;
if (start != 0 && now - start > session.getLockTimeout()) {
throw DbException.get(ErrorCode.LOCK_TIMEOUT_1, e.getCause(), "");
}
try {
Database database = session.getDatabase();
int sleep = 1 + MathUtils.randomInt(10);
if (database.isMultiThreaded()) {
Thread.sleep(sleep);
} else {
database.wait(sleep);
Database database = session.getDatabase();
int sleep = 1 + MathUtils.randomInt(10);
while (true) {
try {
if (database.isMultiThreaded()) {
Thread.sleep(sleep);
} else {
database.wait(sleep);
}
} catch (InterruptedException e1) {
// ignore
}
long slept = System.nanoTime() / 1000000 - now;
if (slept >= sleep) {
break;
}
} catch (InterruptedException e1) {
// ignore
}
return start == 0 ? now : start;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论