SCEA Part I, SCAJ, SCPJ, SCDJ, SCWCD, SCBCD, SCMAD<br /> <br />"The significant problems we face can not be solved at the same level of thinking we were at when we created them." - Albert Einstein
"I'm not back." - Bill Harding, Twister
"I'm not back." - Bill Harding, Twister
I'm disagreeing a bit with Philippe just for old times' sake...
Using sync blocks is a bit uglier, and can blow up in your face if you're not careful - but the additional level of explicitness may be a good thing.
One problem with sync blocks is that they may give you too much power. If you sync on a monitor other than "this", I think you have a greater chance of creating a deadlock if you're not careful.
So, I'm not really sure I'd recommend one over another in general. Both techniques can work well, or can lead to trouble if not used well.
I read a few posts here where people synchronized Data methods while they had one instance of Data per client. Useless and misleading (except maybe from the grader's perspective).
Why is this useless and misleading? Or do you mean a new instance of Data
for each client is useless and misleading? (rather than having one instance of data for every client?)
SCJP 1.4, SCJD 1.4, SCWCD 1.3, SCBCD 1.3, IBM Certified Solution Developer -WebSphere Studio V5.0
If those synchronized methods belong to the same class, don't care about crossed calls : java the synchronize mechanism is reentrant.
"I'm not back." - Bill Harding, Twister