Reputation:
I am developing an apache Jena application. It works fine when I run the codes from Intellij IDE but if I generate a jar file and run the jar file in terminal it doesn't work.
The error I get:
Uncaught exeption ! : org.apache.jena.dboe.base.file.AlreadyLocked: Failed to get a lock: file='/home/iam/OneDrive/Internship/current_data/myTDB/tdb.lock': Lock already held
I am using:
Upvotes: 0
Views: 217
Reputation: 28636
I would refer to the TDB FAQs as a first reference:
This exception is a result of TDBs automatic multi-JVM usage prevention, as noted in the earlier Can I share a TDB dataset between multiple applications? question a TDB database can only be safely used by a single JVM otherwise data corruption may occur. From 1.1.0 onwards TDB automatically enforces this restriction wherever possible and you will get this exception if you attempt to access a database which is being accessed from another JVM.
Basically you cannot open the same TDB database location from two processes simultaneously.
As for what appears to be happening in your specific case:
Most likely you'll need to begin with quitting and restarting IntelliJ since that process (or a child process) will be the lock holder. You'll then need to make sure that any code you are running from inside IntelliJ is spawned as a fresh process and that you stop that process whenever you want to test your built JAR separately.
Another possible approach would be to make your TDB database location configurable so you use a different location when testing in IntelliJ vs when running the JAR file. That way you avoid any possibility of the two processes competing over database locks because they'd be using separate databases.
I also notice that your database appears to be on a OneDrive location - /home/iam/OneDrive/Internship/current_data/myTDB/tdb.lock
- it is also possible that there is a file system issue happening here.
For 2, which seems the more likely problem in your case, you can try finding out what is holding the lock e.g. How to list processes locking file to figure out what other process is locking it and investigate further.
Upvotes: 1