在idea中线程断点调试

断点

所有的断点都选择线程调试模式
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

代码示例

测试代码

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");
    }
}

猜你喜欢

转载自blog.csdn.net/qq_36336332/article/details/108034358
今日推荐