• Post Reply Bookmark Topic Watch Topic
  • New Topic

XML Read/Write Concurrency Prevention.

 
Agniva Sengupta
Greenhorn
Posts: 16
Java Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Synchronized methods for reading and writing the data.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In case you are planning to use the FileChannel/FileLock, this recent discussion will be worth a read http://www.coderanch.com/t/551144/java/java/File-lock-doesn-prevent-threads
 
Agniva Sengupta
Greenhorn
Posts: 16
Java Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 52580
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Too difficult a question for "beginning". Moving, not sure where the best location is, but let's try "synchronization".
 
Agniva Sengupta
Greenhorn
Posts: 16
Java Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!