Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

RMI and resource share

 
Howie Jiang
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am new to RMI. Have this question here.

If more than one client connect to the server, and call a method which will modify the same resouce, eg. an integer. How does RMI handle this kind of problem?

If the method being called by two client at the same time, will it be queued for excution?

I writing a test program as follows:

on Server:
int i; //initial value is 0
public int getI() {
int k = i;

//----- below is just simulating the program do sth else
int t = 0;
for (int g=0; g<1000; g++)
t=g;
//-------------------------

i++;
return k;
}

Each time client connect to server and call getI(), i will be increased by 1. At the client side, i will print the returned value. However, I found that if there are two clients, they will print a lot of same value.

How can I solve this kind of resouce share problem in RMI?

thanx
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RMI just uses a separate thread for each client accessing the server... so for cases like this to work correctly, you'd need to make your server object thread safe. (You can look in the Threads and Synchronization forum here on the ranch for more info about this.)
 
pete wontner
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am after clarification regarding RMI and thread pools. I have seen numerous articles claiming that the sun RMI implementation supports a Thread Pool for method invocations. I have also seen numerous articles saying the the sun RMI implementation does not implement a Thread Pool. Can someone confirm once and for all which is it?
I want to use RMI (or JINI) to build a scalable data server, servicing many client applications, but thread pooling is almost a pre-requisite to enable decent scalability.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Everything I've seen says that it uses a Thread pool. Can you post some links to the sources that say it doesn't? Maybe an older implementation of RMI didn't, and the articles are just old...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!