synchronized实际上是利用对象锁保证临界区的代码的原子性,临界区的代码对外是不可分割的不会被线程切换所打断 synchronized锁的深入了解 偏向锁 上面的锁是锁住的是同一个对象,method1中调用了method2是一种可重入锁 使用synchronized操作系统会创建一个monitor对象,monitor对象中有三个部分 WaitSet, EntryList, Owner 而使用了volatile不会 notify()是随机叫醒一个正在waitSet中等待的线程进入entryList 正确姿势 volatile是轻量级锁 synchronized是重量级锁