Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes The RmiNoFactoryExample (Monkhouse and Camerlengo) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "The RmiNoFactoryExample (Monkhouse and Camerlengo)" Watch "The RmiNoFactoryExample (Monkhouse and Camerlengo)" New topic
Author

The RmiNoFactoryExample (Monkhouse and Camerlengo)

Alexandru Dragoi
Ranch Hand

Joined: May 09, 2008
Posts: 30
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


Alex Dragoi, SCJP 1.4, OCPJP 6
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5545
    
  13

Hi Alex,

It's not listed in the errata of the book on the Apress website, but that was last updated in 2006 (so I guess it isn't maintained anymore).

The statement seems a bit inconsistent with the name of the application, because that suggests (and the output confirms) there is only one DvdDatabase object created which both threads invoke methods on through RMI. It's a statement you would expect with the RmiFactoryExample example.

Kind regards,
Roel


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
 
 
subject: The RmiNoFactoryExample (Monkhouse and Camerlengo)