Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File Writes Are Not Thread Safe #51

Open
RickeyWard opened this issue Sep 15, 2021 · 2 comments
Open

File Writes Are Not Thread Safe #51

RickeyWard opened this issue Sep 15, 2021 · 2 comments

Comments

@RickeyWard
Copy link

RickeyWard commented Sep 15, 2021

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.

@FarooqKhan
Copy link
Collaborator

FarooqKhan commented Sep 25, 2021

@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.

@sebastian-mrozek
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants