File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Detecting another running JVM from a JVM! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Detecting another running JVM from a JVM!" Watch "Detecting another running JVM from a JVM!" New topic
Author

Detecting another running JVM from a JVM!

Richard Levy
Greenhorn

Joined: Jan 19, 2005
Posts: 22
Hi all,

we're running a web application on Oracle 10g (OC4J 9.04) and have hit a snag with OC4J. On each running server, there are TWO JVMs running the same web application, for resilience. The application server balances the load across these 2 JVMs.

The startup & logging config is taken from a database, therefore both JVMs get started the same way, as read the same config. This config contains the log filename. So, both JVMs are writing to the same logfile.

Now, log4j isnt designed to run like this, and lo & behold, sometimes one of the JVMs cant write to the log (I guess because the other one is). What we need is to be able to identify each JVM uniquely.

Initially I thought we could pass an ID parameter in the startup. We could then append this ID to the name of the logfile and we'll have to unique logfiles. However, this cannot be done.

Is there a way to get one JVM detect another JVM. Or does each JVM have a "creation" date that I can get hold of? I know I could have the 2 JVM talk to each other over an open socket and negotiate which one is which, but I'd like to exhaust all simple solutions befoer going to a more complex one.

Any ideas?

Thanks
Richard
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
The socket approach is common. They don't really need to communicate and negotiate much. They just both try to open a server socket on the same port. The first one in will succeed, the second will fail. If you really need the server socket open, you could increment the port and try again.

In my current system we have a configuration table with the ip and port for each clone in the cluster, and some sockets-based administration stuff that can query status or send commands to all clones. JMS/JMX would be a better solution, but this code pre-dates those by quite a while.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Richard Levy
Greenhorn

Joined: Jan 19, 2005
Posts: 22
Hi

Thanks for the tips.

I went with the ServerSocket approach in the end as we will have a max of 2 JVMs per machine, so it was a simple process.

Thanks
Richard
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Detecting another running JVM from a JVM!