提交 38a4c617 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Fix possible ConcurrentModificationException in OnExitDatabaseCloser

上级 b4d3e4a5
......@@ -20,7 +20,13 @@ class OnExitDatabaseCloser extends Thread {
private static boolean registered;
private static boolean terminated;
static synchronized void register(Database db) {
if (terminated) {
// Shutdown in progress
return;
}
DATABASES.put(db, null);
if (!registered) {
// Mark as registered unconditionally to avoid further attempts to register a
......@@ -41,6 +47,11 @@ class OnExitDatabaseCloser extends Thread {
}
static synchronized void unregister(Database db) {
if (terminated) {
// Shutdown in progress, do nothing
// This method can be called from the onShutdown()
return;
}
DATABASES.remove(db);
if (DATABASES.isEmpty() && registered) {
try {
......@@ -54,11 +65,8 @@ class OnExitDatabaseCloser extends Thread {
}
}
private OnExitDatabaseCloser() {
}
@Override
public void run() {
private static synchronized void onShutdown() {
terminated = true;
RuntimeException root = null;
for (Database database : DATABASES.keySet()) {
try {
......@@ -86,4 +94,12 @@ class OnExitDatabaseCloser extends Thread {
}
}
private OnExitDatabaseCloser() {
}
@Override
public void run() {
onShutdown();
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论