java - What does 'synchronized' mean? -


i have questions regarding usage , significance of synchronized keyword.

  • what significance of synchronized keyword?
  • 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:

synchronized methods 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

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -