Hello,
I am reading the RmiNoFactoryExample found in the Monkhouse & Camerlengo book and I am confused by a remark made in the book regarding this example.
For those who do not know, here is a slightly modified version of RmiNoFactoryExample class ( I added this line
remote.findDVD("aa");)
Now the output from running the example is this:
constructing a DvdDatabase object 1222033772. Thread is: main
getting a remote handle to a DvdDatabase.1649083229
calling findDvd on this DvdDatabase object 1222033772. Thread is: RMI TCP Connection(2)-192.168.1.107
getting a remote handle to a DvdDatabase.1421571929
calling findDvd on this DvdDatabase object 1222033772. Thread is: RMI TCP Connection(2)-192.168.1.107
But the conclusion from the authors is this:
The RmiNoFactoryExample constructs only one (i.e. instance of DvdDatabase object). This demonstrates how RMI reuses threads. Each thread has a separate DvdDatabase object, but since the RmiNoFactoryExample reuses one of the threads, the DvdDatabase instance is shared between the two remote invocations.
Indeed, if running this example both clients will reuse the same RMI server thread when calling
findDVD method. I understand that RMI may reuse the server threads between method invocations.
But I find this wrong:
Each thread has a separate DvdDatabase object
It is not true... there is only one DvdDatabase object on the server JVM and all RMI threads will share this instance.
I have built an example where the 2 clients were running on different JVM's and here is the result (on the server side):
constructing a DvdDatabase object 1522234469. Thread is: main
calling findDvd on this DvdDatabase object 1522234469. Thread is: RMI TCP Connection(4)-192.168.1.107
calling findDvd on this DvdDatabase object 1522234469. Thread is: RMI TCP Connection(6)-192.168.1.107
Here you can see that both clients are calling the
findDVD method on the same instance 1522234469. But the difference is that the 2 method invocations (from each client) will spawn 2 different threads on the RMI server.
I do not think the conclusion in the book is OK, because as you can see there is only one instance of DvdDatabaseImpl on the server side at any time, and all the threads will share this instance. What is your opinion about this remark in the book?
Best regards,
Alex