• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

XML Read/Write Concurrency Prevention.

 
Greenhorn
Posts: 16
Oracle Tomcat Server Java
  • 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?
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Synchronized methods for reading and writing the data.
 
Rancher
Posts: 43016
76
  • 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.
 
Bartender
Posts: 11445
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • 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 https://coderanch.com/t/551144/java/java/File-lock-doesn-prevent-threads
 
Agniva Sengupta
Greenhorn
Posts: 16
Oracle Tomcat Server Java
  • 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
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • 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.
 
Marshal
Posts: 70248
282
  • 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
Oracle Tomcat Server Java
  • 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.
 
Let's get him boys! We'll make him read this tiny ad!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic