• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How many instances of remote object should be built in multi-client system?

 
Along huang
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use RMI to implement comunication in my assignment,but I find a problem.

Assume here is a remote object named DataMgr, the sample code as below:

String url = "localhost/DataMgr";
DataMgr dataMgr = new DataMgrImpl();
Naming.rebind(url,dataMgr);

As above,I have only created a instance of DataMgr, if many clients access the remote object simultaneously, what is happen? whether the server build a new instance of DataMgr for client's request automatically?

Or should do I create many instances at initial state of server?

thanks
 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Along:
I am not an expert on RMI, but I will explain this according to my understanding. When a client ask for an object from the server, the server returns a sub, which represents the object. The server doesn't create any new objects, and you don't need to creat any new objects either. If the remote object does any IO operation, and you want to make it thread safe, then you must implement synchronization mechanism to ensure data intigrity.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Along,

In the case you described, there will only ever be one instance of DataMgrImpl, and (as Hanna mentioned) there may be multiple threads running on this one instance, so you will need to make it thread safe.

This may be sufficient for your needs if your Data class uses cookies and/or you are using thin client bookings.

Regards, Andrew
 
Along huang
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for response.

I have more a question about thread, a remote method below:

public int calc(int initialization){
initialization = initialization / 10;
int count = 100 + initialization;
return count;
}

Assuming here are two clients invoking the remote method at a same time:
1). System.out.println(xxx.calc(20));
2). System.out.println(xxx.calc(50));

The method is not set as Synchronized, whether each of the two remote clients can return the correct value?

I know if two threads share a resource outside method, confusion will occur. But in this case showed above,the resource(variable "initialization") is inside method.

Substantively, I think that concern the assignment of memory,i.e.,when many thread access a method of a object simultanenously, system assign a memory for each thread, or only a menory for all thread?

regards
 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi huang :
I don't know what you mean by the system will assign memory to each client. When a thread invoke a method, a stack will be created and each thread will get its own stack and its own version of the local variabls. If the method doesn't use any external parameters (i.e instance varaibles) ro share any external resources (i.e. db file), then it is thread safe.
[ June 18, 2004: Message edited by: Hanna Habashy ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic