Skip to content

Commit abd2c47

Browse files
BoxStore: access thread pool field via getter, use convenience to submit
Best practice Java. Also prevent public access to internalThreadPool().
1 parent f62b910 commit abd2c47

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ public void close() {
731731
}
732732

733733
// When running the full unit test suite, we had 100+ threads before, hope this helps:
734-
threadPool.shutdown();
734+
internalThreadPool().shutdown();
735735
checkThreadTermination();
736736
}
737737
}
@@ -744,12 +744,12 @@ public void close() {
744744
}
745745

746746
/**
747-
* Waits briefly for the internal {@link #threadPool} to terminate. If it does not terminate in time, prints stack
748-
* traces of the pool threads.
747+
* Waits briefly for the internal {@link #internalThreadPool()} to terminate. If it does not terminate in time,
748+
* prints stack traces of the pool threads.
749749
*/
750750
private void checkThreadTermination() {
751751
try {
752-
if (!threadPool.awaitTermination(1, TimeUnit.SECONDS)) {
752+
if (!internalThreadPool().awaitTermination(1, TimeUnit.SECONDS)) {
753753
getErrorOutput().println("ObjectBox thread pool not terminated in time." +
754754
" Ensure all async calls have completed and subscriptions are cancelled before closing the Store." +
755755
"\nPrinting pool threads...");
@@ -1137,7 +1137,7 @@ public <R> R callInTxNoException(Callable<R> callable) {
11371137
* See also {@link #runInTx(Runnable)}.
11381138
*/
11391139
public void runInTxAsync(final Runnable runnable, @Nullable final TxCallback<Void> callback) {
1140-
threadPool.submit(() -> {
1140+
internalScheduleThread(() -> {
11411141
try {
11421142
runInTx(runnable);
11431143
if (callback != null) {
@@ -1158,7 +1158,7 @@ public void runInTxAsync(final Runnable runnable, @Nullable final TxCallback<Voi
11581158
* * See also {@link #callInTx(Callable)}.
11591159
*/
11601160
public <R> void callInTxAsync(final Callable<R> callable, @Nullable final TxCallback<R> callback) {
1161-
threadPool.submit(() -> {
1161+
internalScheduleThread(() -> {
11621162
try {
11631163
R result = callInTx(callable);
11641164
if (callback != null) {
@@ -1330,11 +1330,11 @@ public void setDbExceptionListener(@Nullable DbExceptionListener dbExceptionList
13301330

13311331
@Internal
13321332
public Future<?> internalScheduleThread(Runnable runnable) {
1333-
return threadPool.submit(runnable);
1333+
return internalThreadPool().submit(runnable);
13341334
}
13351335

13361336
@Internal
1337-
public ExecutorService internalThreadPool() {
1337+
ExecutorService internalThreadPool() {
13381338
return threadPool;
13391339
}
13401340

0 commit comments

Comments
 (0)