aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes RemoteData Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "RemoteData" Watch "RemoteData" New topic
Author

RemoteData

Bigwood Liu
Ranch Hand

Joined: Feb 26, 2003
Posts: 240
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
SrinivasMA Srini
Greenhorn

Joined: Feb 21, 2003
Posts: 28
In my assignment remote methods are synchronized
Cheers
Srinivas
SCJP, SCJD
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
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
Bigwood Liu
Ranch Hand

Joined: Feb 26, 2003
Posts: 240
Hi Jim,

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 ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: RemoteData