This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
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.
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
Joined: Jan 19, 2005
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.