• Post Reply Bookmark Topic Watch Topic
  • New Topic

Synchronization between JVMs?

 
Adrian Pang
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!