aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Client-server design Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Client-server design" Watch "Client-server design" New topic
Author

Client-server design

Mathew Ung
Greenhorn

Joined: Jan 18, 2006
Posts: 11
Hi,

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....

Are there alternate designs that perform better ?

thanks in advance,

Matt
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11481
    
  94

Hi Mathew,

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.

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Aruneesh Salhotra
Ranch Hand

Joined: May 12, 2004
Posts: 167
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.
Zhixiong Pan
Ranch Hand

Joined: Jan 25, 2006
Posts: 239
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
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11481
    
  94

Hi Zhixiong,

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.

Regards, Andrew
Zhixiong Pan
Ranch Hand

Joined: Jan 25, 2006
Posts: 239
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: Client-server design