Ajay Verma

Greenhorn
+ Follow
since Aug 03, 2000
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ajay Verma


I am in a delimma. Some facts
1. The assignment says that concurrent use of the database when booking flights from multiple clients should be provided. This means that concurrent access of different records from multiple clients has to be provided.
This implies that the methods in the Data implementation class on the server side cannot be synchronized. Otherwise concurrent access would not be possible.
2. The remote method request from each client to the server object is going to be as a seperate thread (most likely it is going to be from a different JVM and as per the RMI specs calls originating from different client virtual machines will execute in different threads).
This implies that the Data class on the server side needs to be made thread safe. How do we do that ?
Lets take one of the methods getRecord(int rec) . Lets say the first client wants to get the 5th record. He has to seek to the 5th record and then read it. The second client at the same time wants to read the 10th record. So he has to seek to the 10th record and then read it. If the method getRecord(int rec) is not synchronized it is possible between the time the first client seeks to the 5th record and starts reading it, the second client seeks to the 10th record. This causes the first client to read the 10th record insead of the 5th that he was supposed to. from the above arguemnt it seems that the method getRecord(int rec) needs to be synchronized.
Now I am in a delimma from discussion at (1) I conclude do not synchronize the methods while from discussion at (2) I conclude synchronize the methods.
Could anyone help me in removing my delimma.
For some time I felt that for each request by the client a new instance of the server side object (implementation of Data) is created and hence the seeks of one request is unrelated to the seeks of the other. But now I feel that only one instance of the server side object exists. That object is created by the server class which provides the Data service. Multiple instances of proxies (stub) to the server side object is created.
thanks in advance