Low level locking
什么时候需要synchronized ?
一个变量有可能被多个线程访问,其中至少有一个线程是写操作
每个对象都有一个相关的lock对象(监视器)
java语言没有提供分离的lock和unlock操作 ,但是在JVM提供了两个单独的指令monitorenter和monitorext来实现
synchronized的特性
Atomicity :Locking to obtain mutual exclusion
Visibility :Ensuring that changes to object fields made in one thread are seen in other threads(memory)
Ordering: Ensuring that you aren’t surprised by the order in which statements are executed
Blocking:Can’t interrupt



