File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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


Bigwood Liu
Ranch Hand

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

Joined: Feb 21, 2003
Posts: 28
In my assignment remote methods are synchronized
Jim Yingst

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.
[ June 08, 2003: Message edited by: damu liu ]
I agree. Here's the link:
subject: RemoteData
It's not a secret anymore!