St.Antario
St.Antario

Reputation: 27435

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?

Upvotes: 0

Views: 3259

Answers (2)

weberjn
weberjn

Reputation: 1985

A RMI server can be run in Tomcat, a good place to start it up is a ServletContextListener.

With LocateRegistry.createRegistry(port) you don't even need an external rmiregistry.

Nowadays people would use an HTTP based protocol like REST to host a service in a server like Tomcat, but RMI still works and is way faster and easier to use than HTTP.

Upvotes: 1

k.nieszporek
k.nieszporek

Reputation: 135

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.

Upvotes: 0

Related Questions