Hi, my RemoteData implements the DataInterface and Remote, have all the public method in Data except the lock/unlock. I write all methods that write info to the db.db with synchronized key word: public synchronized void add(String  newData) public synchronized void modify(DataInfo newData) public synchronized void delete(DataInfo toDelete) public synchronized void close() throws RemoteException; am i right? regards damu
my RemoteData implements the DataInterface and Remote, Is DataInterface something you wrote, which declares all its methods to throw RemoteException? If so, great. If not though, if DataInterface is an interface specified by Sun (in my assignment it's called the DB interface) and its methods do not throw RemoteException, then you have a problem. RMI will not work if the methods of a Remote object are not declared to throw RemoteException. (rmic will complain when you try to generate stub files.) Hm, I'm not sure making the RemoteData methods synchronized is very useful. When you make a method synchronized, it uses the "this" instance (the current instance of RemoteData in this case) as the momitor - so no other threads can invoke another synchronized method at the same time using that RemoteDate instance. But there may be many different RemoteDate instances on the server - one per client. And so two different clients can invoke update() simultaneously, because they use two different RemoteDate instances. If these two RemoteData instances forward their calls to a single shared Data instance (which is what many of us are doing - see this thread for example), then that Data instance is receiving simultaneous call. So it's not very useful to synchronize RemoteData - you still need to provide thread-safety for the Data class. If RemoteData has instance data of its own (other that a reference to the Data instance) which needs protecting from other threads, then maybe there's a need for synhronization here. But I think you shouldn't need any sync in RemoteDate - just put it in Data.
"I'm not back." - Bill Harding, Twister
Joined: Feb 26, 2003
Thank you very much. You are great!
You clarified me. I did think to use one Data per RemoteData, but now I know it is wrong. Because thus those synchronized methods in Data will be useless. I mean the synchronized methods in Data only synchronized with its own instance, then when a Data is operating the b.db the other Data can still operate it. In addition, my Data class implements DataInterface. Do you think it is ugly that I write a DataInterface implemented by Data and its methods throws RemoteException which is only useful for remote call? But no RemoteException will cause problem. Regards, Damu [ June 08, 2003: Message edited by: damu liu ]