Add debug code for fixing https://bugs.freenetproject.org/view.php?id=6187
- As explained in the commits, the database leak is likely due to a thread missing synchronization. Luckily, Java supports checking whether a lock is taken.