Benefits and disadvantages of using java rmi
Asked Answered
N

2

11

What are the advantages and disadvantages of RMI?

Noonan answered 26/2, 2010 at 6:25 Comment(0)
P
12

The advantages and disadvantages are similar to those of any RPC-like (Remote Procedure Call) System. There is a superficial appearance of simplicity, because it objects which are in fact remote can be treated as though they were local.

This would seem like a great benefit to simplicity of programming, but there are hidden costs. Distributed systems have issues of latency and potential for partial failure which the programmer has to be aware of. An invocation of a remote method is subject to potential failure from security, latency problems, network failure, etc. Papering over these sorts of problems can be a disaster for reliability.

Profundity answered 26/2, 2010 at 6:39 Comment(3)
Thanks for the link to the paper. I can perfectly use this in my thesis :)Weakminded
Well said. Even though I wrote a book on RMI I'm not actually an advocate. It makes things appear simple that are very far from simple, and it makes things hard that actually aren't that hard, e.g. 'should I retry?'Acadian
Not anymore link to "Waldo et al" :|Charleencharlemagne
D
5

From my experience:

Pros:

  • Easy to start
  • Dynamic class loading is very powerful
  • If you implement something like below you can not change server side for a long time and develop client (one exception on rmi server has to get these classes in classpath - so either server them over net or include them and rebuild server)

You can implement two interfaces like that:

Common task interface:

public interface Task<T extends Serializable> extends Serializable {

    T execute();

}

Rmi interface:

public interface RmiTask extends Remote {

    <T extends Serializable> T executeTask(Task<T> task) throws RemoteException;

}

RmiTask implementation on server side:

public class RmiTaskExecutor implements RmiTask {

    public <T extends Serializable> T executeTask(Task<T> task) {
        return task.execute();
    }

}

Example client Task implementation:

public class IsFileTask implements Task<Boolean> {

    final String path;

    public IsFileTask(String path) {
        this.path = path;
    }

    public Boolean execute() {
        return new File(path).isFile();
    }

}

Cons:

  • Could be insecure, when using Dynamic class loading (client serves implementation of passed types) - for example you know that rmi server calls method() on PassedObject, but marvellous client could override this method and execute whatever he wants there...
  • hard to implement callback which would work over Internet (it needs to establish new connection from server to client - it can be challenging to pass it through NAT/routers/ firewalls)
  • when you suddenly broke the connection during execution of remote method it happens that this method would not return (I recommend wrapping rmi calls into Callables and run them with defined timeouts).
Dimaggio answered 30/10, 2012 at 19:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.