Unverified 提交 b172c099 authored 作者: Andrei Tokar's avatar Andrei Tokar 提交者: GitHub

Merge pull request #1657 from h2database/panic-bkg

Failure to stop background thread
...@@ -186,21 +186,20 @@ public class FileStore { ...@@ -186,21 +186,20 @@ public class FileStore {
* Close this store. * Close this store.
*/ */
public void close() { public void close() {
if(file != null) { try {
try { if(file != null && file.isOpen()) {
if (fileLock != null) { if (fileLock != null) {
fileLock.release(); fileLock.release();
fileLock = null;
} }
file.close(); file.close();
freeSpace.clear();
} catch (Exception e) {
throw DataUtils.newIllegalStateException(
DataUtils.ERROR_WRITING_FAILED,
"Closing failed for file {0}", fileName, e);
} finally {
file = null;
} }
} catch (Exception e) {
throw DataUtils.newIllegalStateException(
DataUtils.ERROR_WRITING_FAILED,
"Closing failed for file {0}", fileName, e);
} finally {
fileLock = null;
file = null;
} }
} }
......
...@@ -2845,19 +2845,20 @@ public class MVStore implements AutoCloseable { ...@@ -2845,19 +2845,20 @@ public class MVStore implements AutoCloseable {
// which should not happen with non-weak flavour of CAS operation, // which should not happen with non-weak flavour of CAS operation,
// but I've seen it, so just to be safe... // but I've seen it, so just to be safe...
BackgroundWriterThread t; BackgroundWriterThread t;
while ((t = backgroundWriterThread.get()) != null && while ((t = backgroundWriterThread.get()) != null) {
// if called from within the thread itself - can not join
t != Thread.currentThread()) {
if (backgroundWriterThread.compareAndSet(t, null)) { if (backgroundWriterThread.compareAndSet(t, null)) {
synchronized (t.sync) { // if called from within the thread itself - can not join
t.sync.notifyAll(); if (t != Thread.currentThread()) {
} synchronized (t.sync) {
t.sync.notifyAll();
}
if (waitForIt) { if (waitForIt) {
try { try {
t.join(); t.join();
} catch (Exception e) { } catch (Exception e) {
// ignore // ignore
}
} }
} }
break; break;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论