• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

RemoteData

 
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my assignment remote methods are synchronized
Cheers
Srinivas
SCJP, SCJD
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bigwood Liu
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic