Skip to content

Commit c75755b

Browse files
BoxStore: ensure same file open thread is configured and joined.
Also make defensive copy before checking nullability.
1 parent 239fe8f commit c75755b

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

objectbox-java/src/main/java/io/objectbox/BoxStore.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,16 +276,19 @@ static boolean isFileOpen(final String canonicalPath) {
276276
synchronized (openFiles) {
277277
if (!openFiles.contains(canonicalPath)) return false;
278278
}
279-
if (openFilesCheckerThread == null || !openFilesCheckerThread.isAlive()) {
279+
Thread checkerThread = BoxStore.openFilesCheckerThread;
280+
if (checkerThread == null || !checkerThread.isAlive()) {
280281
// Use a thread to avoid finalizers that block us
281-
openFilesCheckerThread = new Thread(() -> {
282+
checkerThread = new Thread(() -> {
282283
isFileOpenSync(canonicalPath, true);
283-
openFilesCheckerThread = null; // Clean ref to itself
284+
BoxStore.openFilesCheckerThread = null; // Clean ref to itself
284285
});
285-
openFilesCheckerThread.setDaemon(true);
286-
openFilesCheckerThread.start();
286+
checkerThread.setDaemon(true);
287+
288+
BoxStore.openFilesCheckerThread = checkerThread;
289+
checkerThread.start();
287290
try {
288-
openFilesCheckerThread.join(500);
291+
checkerThread.join(500);
289292
} catch (InterruptedException e) {
290293
e.printStackTrace();
291294
}

0 commit comments

Comments
 (0)