In my design for the client-server app I have one instance of the server that deals with all client requests. I have synchronised all methods that should not have two threads running concurrently through them.
Would this approach affect performance ? If a thread have to wait for another thread to release a lock to execute a method, this will slow down performance....but Iam not sure there is any other solution....
I assume you are talking about synchronizing methods in the Data class - is that correct? Or are you talking about synchronizing methods in the methods exposed through your server?
This will probably impact concurrency (which is something the instructions mention your server has to be capable of). To give you an example:[*]Client A wishes to lock record 5[*]Client B wishes to read record 7
Is there any reason why these two operations cannot logically run at the same time? If you have synchronized methods, then they cannot run concurrently.
For that matter, even within a method like read(), there is room for improving concurrency (unless you are working with a cache, in which case your read() method may be very minimalistic). But assuming you don't have a cache, you are going to have to seek to a location in the file, and read the bytes from the file. From that point onwards, all the data is in memory, so you can do your check on whether the record has been deleted and conversion to a String outside of a synchronized block, thereby improving concurrency.
Without keeping a in memory replica of the DB file, it is going to be a very tedious process, and I wonder if that would be really liked by Sun. Atleast that is what I think, for read operations, or find record, disk IO is bad.
I think if you can, you should change the design to have a array of vectors or likewise to have in-memory replica.
Hi Andrew, I also have problems in designing server-client.Your advice above gave me illumination. If lock() should not be synchronizing, then how about other method such as unlock() and update().When talking about read(), i am not clearly get what you mean cashe, would you please explain more details about it?
SCJP 1.4 SCJD
author and jackaroo
I didn't say that synchronization of some sort is not required, just that synchronization at a method level may not provide good concurrency (and concurrent operations is something listed in the instructions as being desirable).
In general this is the way I prefer to operate: I try not to force my ideas onto candidates, but just make suggestions and comments on design concepts that they discuss.
As for a cache - some candidates prefer to keep a copy of the database in memory on the server. Then when a client calls read(5) (for example) the contents of record number 5 will be retrieved from the in-memory copy of the data, rather than retrieving the data from disk. This is referred to as a cache.
Joined: Jan 25, 2006
Hi Andrew, Thanks for your reply.Now i know that my read() is from cache, as i already have design a method to get data from db file and in such method a Vector was created to store data.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com