@@ -82,6 +82,8 @@ public class BoxStore implements Closeable {
8282
8383 /** The ObjectBox database version this Java library is known to work with. */
8484 private static final String VERSION = "4.3.1-2025-08-02" ;
85+
86+ private static final String OBJECTBOX_PACKAGE_NAME = "objectbox" ;
8587 private static BoxStore defaultStore ;
8688
8789 /** Currently used DB dirs with values from {@link #getCanonicalPath(File)}. */
@@ -753,28 +755,43 @@ private void checkThreadTermination() {
753755 if (!internalThreadPool ().awaitTermination (1 , TimeUnit .SECONDS )) {
754756 getErrorOutput ().println ("ObjectBox thread pool not terminated in time." +
755757 " Ensure all async calls have completed and subscriptions are cancelled before closing the Store." +
756- "\n Printing pool threads..." );
758+ "\n Dumping stack traces of threads on the pool and any using ObjectBox APIs:" +
759+ "\n === BEGIN OF DUMP ===" );
757760 // Note: this may not print any pool threads if other threads are started while enumerating
758761 // (and the pool threads do not make it into the threads array).
759762 Thread [] threads = new Thread [Thread .activeCount ()];
760763 int count = Thread .enumerate (threads );
761764 for (int i = 0 ; i < count ; i ++) {
762765 Thread thread = threads [i ];
763- if (thread . getName (). startsWith ( ObjectBoxThreadPool . THREAD_NAME_PREFIX )) {
766+ if (shouldDumpThreadStackTrace ( thread )) {
764767 getErrorOutput ().println ("Thread: " + thread .getName ());
765768 StackTraceElement [] trace = thread .getStackTrace ();
766769 for (StackTraceElement traceElement : trace ) {
767770 getErrorOutput ().println ("\t at " + traceElement );
768771 }
769772 }
770773 }
771- getErrorOutput ().println ("Printing pool threads...DONE " );
774+ getErrorOutput ().println ("=== END OF DUMP === " );
772775 }
773776 } catch (InterruptedException e ) {
774777 e .printStackTrace (getErrorOutput ());
775778 }
776779 }
777780
781+ private boolean shouldDumpThreadStackTrace (Thread thread ) {
782+ // Dump any threads of the internal thread pool
783+ if (thread .getName ().startsWith (ObjectBoxThreadPool .THREAD_NAME_PREFIX )) return true ;
784+
785+ // Any other thread might be blocking a thread on the internal pool, so also dump any that appear to use
786+ // ObjectBox APIs.
787+ StackTraceElement [] trace = thread .getStackTrace ();
788+ for (StackTraceElement traceElement : trace ) {
789+ if (traceElement .getClassName ().contains (OBJECTBOX_PACKAGE_NAME )) return true ;
790+ }
791+
792+ return false ;
793+ }
794+
778795 /**
779796 * Danger zone! This will delete all data (files) of this BoxStore!
780797 * You must call {@link #close()} before and read the docs of that method carefully!
0 commit comments