tags:

views:

192

answers:

2

I am using RMI to implement some distributed algorithm, and since we're transmitting quite big objects, I'd like some precisions about when RMI transmits serialized objects over the network.

Suppose I have a Remote classe with the following method.

class MyServer extends Remote {
    public synchronized void foo (Bar bar) {
        ...
        Thread.wait();
        ...
    }
}

Now, I have two (or more) RMI clients calling MyServer.foo method. When Client 1 calls it, it gets blocked in Thread.wait(). Then, Client 2 calls foo and it gets blocked because Client 1 is still in the foo method which is synchronized.

Now, the question is : When is the bar parameter of the Client 2 call transmitted over the network ? Only once Client 2 can actually enter the foo method or before, when it is blocked ?

Bonus question : Is this (the time at which objects are transmitted) a behavior that is enforced by RMI specs or is this implementation-specific ?

+1  A: 

There seems to be a couple of issues with your example.

I assume Thread.wait() is actually this.wait(), since there is no such method on Thread. And the wait should be called on the same object as is used to do the synchronization.

Assuming this, when Client 1 calls the lock.wait(), the monitor on the synchronization block is released. This means that Client 2 can access the method and will eventually block at the same wait method. The wait() will release when some other thread calls a notify() on the same instance of MyServer.

As for serialization, that occurs before this method is called. It would have occurred within the RMI code which calls this method.

Robin
+1  A: 

The bar parameter is transmitted in the same request as the request to invoke the foo method, which is part of the RMI protocol.

nos