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

Fix possible ConcurrentModificationException in OnExitDatabaseCloser

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