What should you do such that an RMI server program can accept multiple clients and actually parallelize their execution?

Sameer Tyagi

Well first theres nothing you can do explicitly for this. This IS the way it works. Multiple client calls to the same object are NOT queued up but concurrent method invocations on an RMI object are automatically executed in separate threads as necessary. Serial invocations from the same client are processed in the same thread as an optimization.

According to the rmi specs
> "A method dispatched by the RMI runtime to a
> remote object implementation (a server) may or may not execute in a
> separate thread. Some calls originating from the same client virtual
> machine will execute in the same thread; some will execute in different
> threads. Calls originating from different client virtual machines will
> execute in different threads. Other than this last case of different
> client virtual machines, the RMI runtime makes no guarantees with
> respect to mapping remote object invocations to threads. "

What this means is that if you are maintaining state in the object between method calls or need syncronization, then the remote method must be synchronized in the interface, or it should use synchronizing in its implementation with synchronize(object){code...}

It also means that that this method will be executed with the lock acquired for the implementation object (not the stub or skeleton). In this case, even though the invocations from the two clients are executed in separate threads, the execution of the method will indeed be mutually exclusive because of the lock on the implementation object.

[In other words, the remote object must be thread-safe. -Alex]
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.