Search code examples
javaclasssocketsserverrmi

Java RMI server: Running servers with different data


I have a question about running multiple servers in JAVA RMI programming.

I should have 3 servers with the same functionality and different data in their hashmaps.

So my question is, could I create one class for servers and run multiple times, or create 3 different classes for servers.


Solution

  • Could I create one class for servers and run multiple times

    Yes. Just supply the different HashMap data in the constructor.

    You'll have to register all three instances in the Registry, under different names, or make them accessible via some other RMI mechanism.

    Contrary to @JunedAhsan's answer, they can all share the same TCP port, and by default they will, if they're all exported from the same JVM, and there's no reason not to do that.