Skip to content

Is it possible to run RMI server in tomcat?

I have two tomact instances, running on Tomcat 7 (call it tomcat 1, tomcat 2). I need to arrange distributed computation. The server tomcat 1 should invoke some method on tomcat 2‘s VM.

Is it even possible to do? I know that Tomcat is a servlet container. Does it support such things?


Yes, it is possible, but you don’t run RMI on Tomcat. You must run rmiregistry on server and connect to this registry form your Tomcat’s. Your application should implement interface extent Remote, and its implementation like in general RMI application. It could be a little hard, because you must register your service twice once for tomcat 1, and second for tomcat 2, it could be done via configuration or hard coded.

Maybe you should consider provide your RMI Server as java application, and invoke there method from Tomcat or read about JMS, it is more common solution today than RMI.