Running Multiple Oracle Coherence Nodes in a JVM

One of the most frequent questions in the Oracle Coherence Support Forums is how to run multiple Coherence nodes within a single JVM. I usually answer the same thing or just let someone else answer something similar:

Coherence nodes are running within the class-loader that loads the Coherence singleton classes. If you create sibling class-loaders each loading their own instance of coherence.jar, you will get multiple Oracle Coherence nodes running within a single JVM, and these nodes are totally independent of one another. You can specify different override files in the different class-paths so that you can configure the different nodes differently. You can even let these nodes connect to different Oracle Coherence clusters thus you can connect multiple TCMP clusters with this JVM.

Java properties for node-specific configuration are not easily usable due to timing issues and because of sharing a single JVM, but it can be made to work (sort of). On the other hand, Java properties are perfectly fine for specifying cluster-wide configuration, e.g. multicast-address and TTL.

Of course, you have to be able to do something within those class-loaders, which becomes tricky due to restrictions on communicating between class-loaders, considering that Coherence cannot be in a common class-loader between nodes.

I decided to put up a simple example, and possibly extend it a bit later with useful usage patterns for communicating between those class-loaders. You can find it in the attached file which contains the framework and an example class (coherencemultinode.test.TestTwoCacheServersTwoStorageDisabled) in the test source folder showing off some of the capabilities.

The example class starts 4 Coherence nodes in a single JVM, two of which are storage disabled. Also, nodes can easily have separate override files loaded from separate directories, they can have different Java properties (this needed a bit of a hack by replacing the Properties instance with a special subclass).

Documentation and some possible extensions come later.

Robert Varga,
19 Sept 2010, 15:49