Thread breakpoint debugging in idea

Breakpoint

All breakpoints select thread debugging mode
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

Code example

Test code

package com.tiger.singleton;

public class SingletonLazy {
    
    
    private SingletonLazy() {
    
     }
    private static SingletonLazy instance = null;

    //不加 synchronized 测试违反单例实验
    public  static SingletonLazy getInstance() {
    
    
        if (instance == null) {
    
    
            instance = new SingletonLazy();
        }
        return instance;
    }
}
package com.tiger.singleton;

/**
 * @description:
 * @author: tiger
 * @create: 2020-08-16 10:59
 */
public class Test {
    
    

    public static void main(String[] args) {
    
    

        Runnable runnable = () -> {
    
    
            System.out.println(Thread.currentThread().getName().concat(":").concat(String.valueOf(SingletonLazy.getInstance())));
        };

        Thread thread1 = new Thread(runnable, "线程1");
        Thread thread2 = new Thread(runnable, "线程2");
        thread1.start();
        thread2.start();

        System.out.println("end");
    }
}

Guess you like

Origin blog.csdn.net/qq_36336332/article/details/108034358