What We Learned in Day 1
We covered how to create threads and use the intrinsic locks built into every
Java object to enforce mutual exclusion between them. We also saw the three
primary perils of threads and locks—race conditions, deadlock, and memory
visibility, and we discussed some rules that help us avoid them:
• Synchronize all access to shared variables.
• Both the writing and the reading threads need to use synchronization.
• Acquire multiple locks in a fixed, global order.
• Don’t call alien methods while holding a lock.
• Hold locks for the shortest possible amount of time.
转载于:https://my.oschina.net/doctor2014/blog/399046

489

被折叠的 条评论
为什么被折叠?



