This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
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?
Tom Farrell
Greenhorn
Joined: Jun 18, 2008
Posts: 3
posted
0
Synchronized methods for reading and writing the data.
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35241
7
posted
0
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.
@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
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.
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32668
4
posted
0
Too difficult a question for "beginning". Moving, not sure where the best location is, but let's try "synchronization".
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.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.