• 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

RMI and object and thread sharing

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I'm doing URLyBIRD 1.1.3 and got the following doubt:

When a client connect to the RMI server, the RMI server shares instances between clients (similar to an object pool) or the server creates a new instance of the object for each client connected?

One more thing: Are threads shared between clients? Or each new client that connects, a new thread will be created for interacting with the remote object and this thread will be exclusively used by that client?

Thanks for the help
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, my buddy.

When a client connect to the RMI server, the RMI server shares instances between clients (similar to an object pool) or the server creates a new instance of the object for each client connected?



Partner, I didn't really get your question... which object are you talking about?

Are threads shared between clients?



When using RMI, when a client calls a remote method, it is not guaranteed that the same Thread that is used by the server in the first time will be used for this same client in their subsequent calls. This means that you cannot use, for instance, the Thread's ID to identify a remote client.
 
Alberto Ridolfi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello mate,

First of all, thanks for the help.

With the question:

When a client connect to the RMI server, the RMI server shares instances between clients (similar to an object pool) or the server creates a new instance of the object for each client connected?



I meant: Let's say I have a class BookingManager which implements BookingRemote, and it is the BookingManager class the one I use with RMI. It is my remote class.

So my doubt is, what happens in regards to instantiation when a client connects to the RMI server and asks to get the object? Each client gets a new instance of the object? Or do they (the remote clients) share the same instance of the class?

So, to give an example: The class has an int field called test, which is initialized to 0. If there are two clients connected (client A and client B), and client A changes the test field to 10, what value client B will see? 10 or 0?



Client A gets the object via RMI registry
Client B gets the object via RMI registry
Client A sees 0
Client B sees 0
Client A changes to 10
Client B sees 10 or 0?

Thank you very much!
[ December 02, 2008: Message edited by: Alberto Ridolfi ]
 
Roberto Perillo
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Or do they (the remote clients) share the same instance of the class?



Yes, they would all access the same class.

This is how I developed my server: Writing an RMI Server. I believe this will help you with this part of the project!
 
Alberto Ridolfi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello mate,

Thanks for the help! That was my doubt :-) I will read the link you sent me.

Cheers
 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the different clients do not share the same instance of a class, instead they share some instances. It's a pool of instances (and threads), and you should never rely on the server executing your code over a fresh new instance, nor on the same instance.

As a guideline: do not make your remote objects stateful.

"The" book (SCJD exam w J5) uses a RMI factory to ensure creation of new remote objects every time a new client connects. This is a way you could get around this "remote object pooling" (the thread pooling cannot be avoided).

I for one did not use this stuff, my database has locking cookies, so I don't need new instances for each client.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic