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

Avoid deadlocks

上级 ee6b0804
...@@ -251,20 +251,26 @@ public abstract class Command implements CommandInterface { ...@@ -251,20 +251,26 @@ 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) {
if (database.isMultiThreaded()) { try {
Thread.sleep(sleep); if (database.isMultiThreaded()) {
} else { Thread.sleep(sleep);
database.wait(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; return start == 0 ? now : start;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论