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