This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Client-server design

 
Mathew Ung
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 11905
207
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Aruneesh Salhotra
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11905
207
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic