| 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.
|
 |
 |
|
|
subject: Synchronization between JVMs?
|
|
|