@@ -358,10 +358,11 @@ static String getCanonicalPath(File directory) {
358358 }
359359 }
360360
361- static void verifyNotAlreadyOpen (String canonicalPath ) {
361+ void verifyNotAlreadyOpen (String canonicalPath ) {
362362 synchronized (openFiles ) {
363- isFileOpen (canonicalPath ); // for retries
363+ boolean fileOpen = isFileOpen (canonicalPath ); // for retries
364364 if (!openFiles .add (canonicalPath )) {
365+ System .out .println ("verifyNotAlreadyOpen failed for " + this + " (fileOpen=" + fileOpen + ")" );
365366 throw new DbException ("Another BoxStore is still open for this directory: " + canonicalPath +
366367 ". Hint: for most apps it's recommended to keep a BoxStore for the app's life time." );
367368 }
@@ -377,7 +378,8 @@ static boolean isFileOpen(final String canonicalPath) {
377378 if (checkerThread == null || !checkerThread .isAlive ()) {
378379 // Use a thread to avoid finalizers that block us
379380 checkerThread = new Thread (() -> {
380- isFileOpenSync (canonicalPath , true );
381+ boolean fileOpen = isFileOpenSync (canonicalPath , true );
382+ System .out .println ("checkerThread retries completed (fileOpen=" + fileOpen + ")" );
381383 BoxStore .openFilesCheckerThread = null ; // Clean ref to itself
382384 });
383385 checkerThread .setDaemon (true );
@@ -403,6 +405,7 @@ static boolean isFileOpenSync(String canonicalPath, boolean runFinalization) {
403405 int tries = 0 ;
404406 while (tries < 5 && openFiles .contains (canonicalPath )) {
405407 tries ++;
408+ System .out .println ("isFileOpenSync calling System.gc() and System.runFinalization()" );
406409 System .gc ();
407410 if (runFinalization && tries > 1 ) System .runFinalization ();
408411 System .gc ();
@@ -529,6 +532,7 @@ public long getDbSizeOnDisk() {
529532 @ SuppressWarnings ("deprecation" ) // finalize()
530533 @ Override
531534 protected void finalize () throws Throwable {
535+ System .out .println ("finalize() called for " + this + " by " + Thread .currentThread ());
532536 close ();
533537 super .finalize ();
534538 }
@@ -654,6 +658,7 @@ public boolean isReadOnly() {
654658 * are properly finished.
655659 */
656660 public void close () {
661+ System .out .println ("close() called for " + this + " (handle=" + handle + ")" );
657662 boolean oldClosedState ;
658663 synchronized (this ) {
659664 oldClosedState = closed ;
@@ -716,6 +721,7 @@ public void close() {
716721 openFiles .notifyAll ();
717722 }
718723 }
724+ System .out .println ("close() finished for " + this );
719725 }
720726
721727 /** dump thread stacks if pool does not terminate promptly. */
0 commit comments