Skip to content

Commit 2d93164

Browse files
BoxStore: shut down and wait briefly on thread pool *before* closing #258
This can help avoid transactions getting closed by force.
1 parent abd2c47 commit 2d93164

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,11 @@ public void close() {
696696
// (due to all Java APIs doing closed checks).
697697
closed = true;
698698

699+
// Stop accepting new tasks (async calls, query publishers) on the internal thread pool
700+
internalThreadPool().shutdown();
701+
// Give running tasks some time to finish, print warnings if they do not to help callers fix their code
702+
checkThreadTermination();
703+
699704
List<Transaction> transactionsToClose;
700705
synchronized (transactions) {
701706
// Give open transactions some time to close (BoxStore.unregisterTransaction() calls notify),
@@ -729,10 +734,6 @@ public void close() {
729734
if (handleToDelete != 0) { // failed before native handle was created?
730735
nativeDelete(handleToDelete);
731736
}
732-
733-
// When running the full unit test suite, we had 100+ threads before, hope this helps:
734-
internalThreadPool().shutdown();
735-
checkThreadTermination();
736737
}
737738
}
738739
if (!oldClosedState) {

0 commit comments

Comments
 (0)