加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

synchronized

(2022-04-12 18:34:10)
标签:

synchronized

分类: java
The synchronized keyword is all about different threads reading and writing to the same variables, objects and resources. 
This is not a trivial topic in Java, but here is a quote from Sun:
synchronized methods enable a simple strategy for preventing thread interference and memory consistency errors: if an object is visible to more than one thread, all reads or writes to that object's variables are done through synchronized methods.

In a very, very small nutshell: When you have two threads that are reading and writing to the same 'resource', say a variable named foo, you need to ensure that these threads access the variable in an atomic way. 
Without the synchronized keyword, your thread 1 may not see the change thread 2 made to foo, or worse, it may only be half changed. This would not be what you logically expect.
有道词典
synchron ...
详细X
Synchronized [' skrnazd] X in detail Basic translation Adj. Synchronization; The synchronization of the V. make coordination (the synchronize the past participle); At the same time; The calibration The network definition Synchronized: synchronous Synchronized Swimming, Synchronized Swimming Synchronized Multimedia Integration Language: Synchronized Multimedia Integration Language

0

阅读 收藏 喜欢 打印举报/Report
前一篇:wait和notify
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有