Hi,
My first idea would be to try and lock the main table of the database, `tbl.basex`, via FileChannel.tryLock(). That should be just as effective in preventing concurrent access, with the added benefit of leaving no orphaned files behind when the BaseX instance isn't terminated gracefully.
yes, I think we should rather go for the lock approach. Still, I'd prefer to create a separate file for each process accessing the database; otherwise, we won't know when to unlock the existing files.
P.S.: You can render the database usable again by deleting the pin-* file by hand.
I have just added a section on lock and pin files to our documentation:
http://docs.basex.org/wiki/Transaction_Management#Locking
As Dimitar indicated, the problem you stumbled upon is a bug (this is a positive side effect of the introduced pin files: we have already found two other bugs related to databases that had not been properly closed).
Christian