java - What does 'synchronized' mean? -
i have questions regarding usage , significance of synchronized keyword.
- what significance of
synchronizedkeyword? - when should methods
synchronized? - what mean programmatically , logically?
the synchronized keyword different threads reading , writing same variables, objects , resources. not trivial topic in java, here quote sun:
synchronizedmethods enable simple strategy preventing thread interference , memory consistency errors: if object visible more 1 thread, reads or writes object's variables done through synchronized methods.
in very, small nutshell: when have 2 threads reading , writing same 'resource', variable named foo, need ensure these threads access variable in atomic way. without synchronized keyword, thread 1 may not see change thread 2 made foo, or worse, may half changed. not logically expect.
again, non-trivial topic in java. learn more, explore topics here on , interwebs about:
keep exploring these topics until name "brian goetz" becomes permanently associated term "concurrency" in brain.
Comments
Post a Comment