aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes NX: Consideration of synchronize methods in Data class or RAF object 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)
Reply locked New topic
Author

NX: Consideration of synchronize methods in Data class or RAF object

Robert Huang
Greenhorn

Joined: Dec 15, 2003
Posts: 9
hi, all
My SCJD Assignment is URLyBird. Now I have some questions about my synchronize design.
In my design, I use the singleton design pattern to implement the remote object(RemoteDataImpl class). That means there is only one instance of remote object running on server and every clinet thread can only obtain the same remote object instance. And the RemoteDataImpl class has a static instance of Data class, which implements the DB interface ( provided from Sun Enterprise) and uses a RandomAccessFile object to interact with the database file. Each client's request, such as "Search" and "book", should be actioned through using some business methods of the unique instance of RemoteDataImpl class, which subsequently call some methods of its static instance of Data class.
Originally, I have two choices to implement the synchronize mechanism. One, synchronize all methods of Data class, which are related to database operations. Two, just synchronize the RAF object. However, after carefully analysis, now I have some questions about my design, which ars as follows:
As mentioned above, every clinet thread can only obtain the same remote object instance through RMI. And the remothe object instance has a static instance of Data class. That means each client can access the physical data file only through the same instance of Data class and RAF object. Thus, no matter I chose to synchronize the methods of Data class or RAF object, if there is a client thread which is implmenting a database action, read or write db file, other client threads have to wait untill that client thread ends its action. On another word, suppose now there are 300 client threads connect to RMI server, at a time point, only one client thread can performes its database action, no matter it's a read or write action, all of the left client threads have to wait to obtain the chance.
I think it probably produce performandce problem and server can't respond quickly to client's request. What I want is all the client threads can read db file simultaniously as long as no client thread performe write actions. Of course, if a client is perform write action in db file, all the other clients have to wait.
Could Andrew Monkhouse,Ken Krebs,and Bill Robertson or someone throw your light on my question? Thanks in advance!

Robert
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11481
    
  94

Hi Robert,
Please don't post the same question more than once. And please allow time for people to read your question and answer it.
I have closed this topic as it is a duplicate of this one
Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: NX: Consideration of synchronize methods in Data class or RAF object