• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Synchronized methods in Data class

 
Baris Dere
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I implemented lock and unlock methods with synchronized blocks. And locking called within update and delete methods of the Data class on the server side. On the client side I didn't implement locking. My question is now.. Must I also set the modifier of all methods of the Data class as synchronized? Some of people did. But why should I do that?

Can someone help me to splve this problem?

Thanks

Regards

Baris Dere
 
YungSheng Chang
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Baris,
I think this is a very fundemental and important question in SCJD. Make sure you know what you mean when you add synchronized on a method. It is actually locking the corresponding object for that thread. Therefore, the question should not be "synchronize all method", it instead should be "overall locking mechanism".
In Max Habibi's book he suggest to synchorize all public methods. If you use the same wrapper class design, maybe it is a good idea. Still, the question goes to your locking mechanism.
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Baris,

And locking called within update and delete methods of the Data class on the server side.


Are you sure it's compatible with your instructions? In mine, locking methods may be called server-side, but only from outside of the update and delete methods.

Regards,

Phil.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic