I have a properties configuration file that is accessed by one application and can be modified by another. I need to ensure the reads and writes are synchronized, so that is where I found Apache's Commons-Configuration2 version of PropertiesConfiguration. The documentation states that access to the file can be synchronized similarly as a Read Write lock. However, I couldn't determine the extent of the lock, is it only between threads in the same application or the entire file itself?
1 Answers
If I understood your question correctly you want to lock and synchronize the config file on your drive.
Process synchronization
And you are right Commons-Configuration2 sync capabilities. It only supports synchronization between threads within the same process (just like most frameworks with build in synchronization features). The Commons-Configuration2 docs have some good examples for thread safety.
File synchronization
Commons-Configuration2 reads the config file to memory and than realeses it. You can delete or modify it while the program is still running. Commons-Configuration2 will not read the file again unless you tell it to do so. If you want to lock the file and prevent modification take a look at FileLocks.
If you want to watch for modification you should have a look at FileWatchers.