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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -