简体   繁体   中英

Java RMI threads on client-side are executing sequentially or concurrently when calling the same remote object?

I am having trouble understanding a specific aspect of java RMI.

There's a client that creates N threads that do a lookup on the RMIregistry:

    Registry rmiRegistry;
    try {
        rmiRegistry = LocateRegistry.getRegistry(8585);
    IGestoreSportello igs = (IGestoreSportello)rmiRegistry.lookup("gestoresportelli");
    ExecutorService s = Executors.newCachedThreadPool();
    for(int i = 0; i < T; i++){
        s.execute(new threadRunner(igs));
    }

Where "gestoresportelli" was previously registered as a service in the Server.

So, as far as my understanding goes, the clients are given all the same reference to the SAME object.

What I am asking here is, when I call a method on this object, is it the CLIENT executing the server's code?

Or is it the server that sequentially calls methods on that object?


So supposing we have:

thread1, thread2, thread3. They all call the same method on the same remote object which was registered on the server.

Do they call it sequentially:

Thread1->RemoteObjectReference.doSomething();
wait thread 1 to finish...
Thread2->RemoteObjectReference.doSomething();
wait thread 2 to finish...
Thread3->RemoteObjectReference.doSomething();

OR concurrently:

Thread1->RemoteObjectReference.doSomething();
Thread2->RemoteObjectReference.doSomething();
Thread3->RemoteObjectReference.doSomething();

all at the same time, even tho that's the same remote object?

I hope I was clear enough. Thanks!

What I am asking here is, when I call a method on this object, is it the CLIENT executing the server's code?

No.

Or is it the server that sequentially calls methods on that object?

It is the server, but sequentiality isn't defined.

Do they call it sequentially

It isn't defined.

OR concurrently:

It isn't defined.

To put that more strongly, the RMI specification states specifically that there are no guarantees about associations between client threads and server threads.

All you can deduce from that is that you cannot assume it is single-threaded.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM