This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Synchronized methods in Data class 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 "Synchronized methods in Data class" Watch "Synchronized methods in Data class" New topic

Synchronized methods in Data class

Baris Dere
Ranch Hand

Joined: Mar 23, 2004
Posts: 31
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?



Baris Dere
YungSheng Chang
Ranch Hand

Joined: Jul 28, 2003
Posts: 44
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.

I play Java for fun.<br /> <br />SCJP / SCJD / SCWCD / SCBCD
Philippe Maquet

Joined: Jun 02, 2003
Posts: 1872
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.


It is sorta covered in the JavaRanch Style Guide.
subject: Synchronized methods in Data class
It's not a secret anymore!