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

Avoid deadlocks

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