Forums Register Login

XML Read/Write Concurrency Prevention.

+Pie Number of slices to send: Send
I've got a XML which is being accessed by two different java applications simultaneously.

I need to ensure that concurrent access is not granted to the two applications, i.e one application can't read or write before the other has finished working with the XML. Upon completion of read/write operation, one application needs to have a mechanism to signal the other application about it's status.

What is the standard procedure of implementing such a process? I understand that this basically boils down to manually implementing a monitor lock on the file, but what's the best method to go about doing this?
+Pie Number of slices to send: Send
Synchronized methods for reading and writing the data.
+Pie Number of slices to send: Send
Java's built-in facilities (like synchronization) won't help if the two apps are running on different JVMs.

Lock files are one way to go about it, or storing the status in a shared database.
1
+Pie Number of slices to send: Send
In case you are planning to use the FileChannel/FileLock, this recent discussion will be worth a read https://coderanch.com/t/551144/java/java/File-lock-doesn-prevent-threads
+Pie Number of slices to send: Send
@Tom Farrell : Synchronization doesn't work !

@Maneesh Godbole : The FileChannel/FileLock mechanism was new, I'll try and see what comes out of this. But the file happens to be in UNIX system. Don't know if the File Lock mechanism can be trusted for safety-critical applications!

@Ulf Dittmer : Storing the status in shared database was what came to my mind initially. Sharing the status and implementing mutex algorithm like Dekker's algorithm/Peterson's algorithm is what I was going to do. But I wanted to make sure that I'm not missing out on some sweeter (read simpler) solution to this problem.
Besides, dedicating a DB table for maintaining status of 1 file doesn't sound nice to me! To my DB admin, it sounds like a trap ! :P
+Pie Number of slices to send: Send
 

Agniva Sengupta wrote:
@Maneesh Godbole : The FileChannel/FileLock mechanism was new, I'll try and see what comes out of this. But the file happens to be in UNIX system. Don't know if the File Lock mechanism can be trusted for safety-critical applications!


Did you even read the discussion in the link? If you had, it would have answered your question already.
+Pie Number of slices to send: Send
Too difficult a question for "beginning". Moving, not sure where the best location is, but let's try "synchronization".
+Pie Number of slices to send: Send
 

Maneesh Godbole wrote:

Agniva Sengupta wrote:
@Maneesh Godbole : The FileChannel/FileLock mechanism was new, I'll try and see what comes out of this. But the file happens to be in UNIX system. Don't know if the File Lock mechanism can be trusted for safety-critical applications!


Did you even read the discussion in the link? If you had, it would have answered your question already.



Yes I did, but it seems like the File Lock mechanism doesn't work well in non-Windows OS. Correct me if I'm wrong, but in that same thread, a person named 'john sal' said , "@Rob yes I tried the same on both windows and unix...it is giving exception on windows whereas allowing to write in unix" which gave me the impression that it's not suitable for UNIX.
Please enjoy this holographic presentation of our apocalyptic dilemma right after this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1138 times.
Similar Threads
Web service security and Authentication
What is the best way to generate XML Response
HttpSession vs Stateful Session EJB
SSO + JAAS
URLyBird RAF multiple instances
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 05:05:51.