I have 10 text files, that I use to store records. In my application, I have couple of operations, e.g write to file and edit file (if the specified line is found I create a temp file and transfer all info there, then delete the old and rename the temp file).
All my clients will have access to the 10 text files, so I want synchronize their activities to maintain data consistency.
I want to lock or synchronize a file if a client is editing or writing, say f1.txt so no other can write/edit to it and increase concurrency by letting another client to edit f2.txt in the same time.
public void writeToFile(String pathname){
File f1 = new File(pathname)
synchronize (f1) {.. // do something}
}
My problem here is that am creating a new file everytime with a specific path.
Please I would appreciate any guidance and help, am you to this.
Thanks