jsondb-core
jsondb-core copied to clipboard
File Writes Are Not Thread Safe
Using this in a simple Servlet container application and ran into concurrency issues where multiple threads are trying to write to the file at the same time. Looked at the code the only write protection is a FileLock, and the java documentation states that
File locks are held on behalf of the entire Java virtual machine. They are not suitable for controlling access to a file by multiple threads within the same virtual machine. (reference)
It should be as simple as marking the io methods synchronized.
I'm happy to do a RP if its welcomed.
@RickeyWard Please create a pull request i will be happy to merge. Please do create unit test cases, We need this to be really stable. Jsondb is used by a lot of people and I would hate to break it because I am unable to test thoroughly.
I'd argue that a JVM-wide lock is actually desired here. It would prevent multiple instances of an app overwriting data (as opposed to lock only preventing multiple threads within a single app)