Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Detecting another running JVM from a JVM!

 
Richard Levy
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Richard Levy
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic