• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

The RmiNoFactoryExample (Monkhouse and Camerlengo)

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
I found a beautiful pie. And a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic