java - Does synchronized affect object members? -


if call object synchronized, can access objects inside object if synchronized? or can access data types?

even though goal protect data, synchronization provides exclusivity around block of code, not piece of data. code outside synchronization blocks (or in blocks use different objects), may alter data trying protect if isn't want.

any correct locking strategy must ensure blocks of code interfere each other hold same lock. includes code interfere copy of run in second thread.

synchronized (myobject) {   // sensitive code } 

locking @ method level shorthand locking this pointer body of method. (or class object static method).


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -