Bootstrap

Java八股文三:Java多线程

三、Java 多线程

1、synchronized
  • 修饰代码块 底层实现,通过 monitorenter & monitorexit 标志代码块为同步代码块。
  • 修饰方法 底层实现,通过 ACC_SYNCHRONIZED 标志方法是同步方法。
  • 修饰类 class 对象时,实际锁在类的实例上面。
  • 单例模式
public class Singleton {
   

    private static volatile Singleton instance = null;

    private Singleton(){
   }

    public static Singleton getInstance(){
   
    if (null == instance) {
   
        synchronized (Singleton.class) {
   
            if (null == instance) {
   
            instance = new 
;