提交 fd791d19 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Use correct time check in Engine.openSession() and throw exception on interrupt

上级 09d28f53
...@@ -196,14 +196,15 @@ public class Engine implements SessionFactory { ...@@ -196,14 +196,15 @@ public class Engine implements SessionFactory {
String cipher = ci.removeProperty("CIPHER", null); String cipher = ci.removeProperty("CIPHER", null);
String init = ci.removeProperty("INIT", null); String init = ci.removeProperty("INIT", null);
Session session; Session session;
for (int i = 0;; i++) { long start = System.nanoTime();
for (;;) {
session = openSession(ci, ifExists, cipher); session = openSession(ci, ifExists, cipher);
if (session != null) { if (session != null) {
break; break;
} }
// we found a database that is currently closing // we found a database that is currently closing
// wait a bit to avoid a busy loop (the method is synchronized) // wait a bit to avoid a busy loop (the method is synchronized)
if (i > 60 * 1000) { if (System.nanoTime() - start > 60_000_000_000L) {
// retry at most 1 minute // retry at most 1 minute
throw DbException.get(ErrorCode.DATABASE_ALREADY_OPEN_1, throw DbException.get(ErrorCode.DATABASE_ALREADY_OPEN_1,
"Waited for database closing longer than 1 minute"); "Waited for database closing longer than 1 minute");
...@@ -211,7 +212,7 @@ public class Engine implements SessionFactory { ...@@ -211,7 +212,7 @@ public class Engine implements SessionFactory {
try { try {
Thread.sleep(1); Thread.sleep(1);
} catch (InterruptedException e) { } catch (InterruptedException e) {
// ignore throw DbException.get(ErrorCode.DATABASE_CALLED_AT_SHUTDOWN);
} }
} }
synchronized (session) { synchronized (session) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论