提交 a7c1080b authored 作者: Thomas Mueller's avatar Thomas Mueller

After closing a database, the writer thread will stop almost immediately…

After closing a database, the writer thread will stop almost immediately (instead of after at most 100 ms). This should avoid error messages in the Tomcat log file after a shutdown.
上级 92169c95
...@@ -95,16 +95,18 @@ public class WriterThread implements Runnable { ...@@ -95,16 +95,18 @@ public class WriterThread implements Runnable {
// wait 0 mean wait forever, which is not what we want // wait 0 mean wait forever, which is not what we want
wait = Math.max(wait, Constants.MIN_WRITE_DELAY); wait = Math.max(wait, Constants.MIN_WRITE_DELAY);
do { synchronized (this) {
while (!stop && wait > 0) {
// wait 100 ms at a time // wait 100 ms at a time
int w = Math.min(wait, 100); int w = Math.min(wait, 100);
try { try {
Thread.sleep(w); wait(w);
} catch (InterruptedException e) { } catch (InterruptedException e) {
// ignore // ignore
} }
wait -= w; wait -= w;
} while (wait > 0 && !stop); }
}
} }
databaseRef = null; databaseRef = null;
} }
...@@ -114,6 +116,11 @@ public class WriterThread implements Runnable { ...@@ -114,6 +116,11 @@ public class WriterThread implements Runnable {
*/ */
public void stopThread() { public void stopThread() {
stop = true; stop = true;
synchronized (this) {
notify();
}
// can't do thread.join(), because this thread might be holding
// a lock that the writer thread is waiting for
} }
/** /**
...@@ -122,7 +129,7 @@ public class WriterThread implements Runnable { ...@@ -122,7 +129,7 @@ public class WriterThread implements Runnable {
*/ */
public void startThread() { public void startThread() {
thread.start(); thread.start();
this.thread = null; thread = null;
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论