Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

RMI and resource share

 
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
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • 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.)
 
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 Spring Java
  • 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...
 
knowledge is the difference between drudgery and strategic action -- tiny ad
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic