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.
The moose likes Threads and Synchronization and the fly likes Synchronization between JVMs? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Synchronization between JVMs?" Watch "Synchronization between JVMs?" New topic
Author

Synchronization between JVMs?

Adrian Pang
Ranch Hand

Joined: Feb 20, 2004
Posts: 40
I have the following situation and I am wondering if any of you can advise on what I can do. I am integrating with an application server that can launch a new JVM to process requests. In my code, I need to be able to synchronize access to a common resource (a file). However, there's no way I can have shared monitor/mutex across multiple JVM -- is there?
{ }[ JVM 1 - Running myCode ]
{ }
{Server }[ JVM 2 - Running myCode ]
{ }
{ }[ JVM 3 - Running myCode ]
In myCode, let's say I always write to a common file debug.log. I need to synchronize access to protect this resource.
The two solutions I thought of is to have another piece of code that listens on a socket and synchronize access, or use JNI since I can share mutex in C++. However, both are very messy.
Any advices? Thanks!
Adrian


SCJP 1.4, SCWCD 1.4, SCBCD 1.3
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

You should put a layer between your clients and the code. I think this is another opportunity for RMI. You could have an RMI class that accesses the file, and only way to access the file is through that program.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Synchronization between JVMs?
 
Similar Threads
Locking Schemes: Tactical View 01
Can someone check my lock/unlock methods, please?
Synchronization of public methods in DVDDatabase
Properties File sharing across Mulipe Web applications
Synchronize a part