IDEA多线程下多个线程切换断点运行调试的技巧

多线程调试设置可以参考:http://www.cnblogs.com/leodaxin/p/7710630.html

1 断点设置如图:

2 测试代码,然后进行debug

复制代码
package com.daxin;

import java.util.HashMap;

/**

  • Created by Daxin on 2017/10/22.
    */
    public class HashMapInfiniteLoop {
    private static HashMap<Integer, Integer> map = new HashMap<Integer, Integer>(2, 0.75f);

    public static void main(String[] args) throws InterruptedException {
    map.put(
    5, 55);

     </span><span style="color: #0000ff;">new</span> Thread("Thread1-Name"<span style="color: #000000;">) {
         </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> run() {
             System.out.println(</span>"Thread1-Name Start"<span style="color: #000000;">);
             </span><span style="color: #0000ff;">try</span><span style="color: #000000;"> {
                 Thread.sleep(</span>5000<span style="color: #000000;">);
             } </span><span style="color: #0000ff;">catch</span><span style="color: #000000;"> (InterruptedException e) {
                 e.printStackTrace();
             }
             map.put(</span>7, 77);<span style="color: #008000;">//</span><span style="color: #008000;">断点位置 1</span>
    

System.out.println(map);
}

    }.start();
    </span><span style="color: #0000ff;">new</span> Thread("Thread2-Name"<span style="color: #000000;">) {

        </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> run() {
            </span><span style="color: #0000ff;">try</span><span style="color: #000000;"> {
                System.out.println(</span>"Thread2-Name Start"<span style="color: #000000;">);
                Thread.sleep(</span>5000<span style="color: #000000;">);
            } </span><span style="color: #0000ff;">catch</span><span style="color: #000000;"> (InterruptedException e) {
                e.printStackTrace();
            }
            map.put(</span>3, 33);<span style="color: #008000;">//</span><span style="color: #008000;"> 断点位置2</span>

System.out.println(map);
}

    }.start();


    </span><span style="color: #008000;">//</span><span style="color: #008000;"> 断点位置 3</span>
    System.out.println("Thread-Main-Name Start"<span style="color: #000000;">);
    System.out.println(</span>"Thread-Main-Name Start"<span style="color: #000000;">);
    System.out.println(</span>"Thread-Main-Name Start"<span style="color: #000000;">);


    Thread.sleep(</span>500000<span style="color: #000000;">);

}

}

复制代码

3:启动debug,我们可以在Threads Tab选项双击需要进行单步调试的线程

然后选择Frames Tab选项中调试的线程进行快捷键调试即可。

 

原文地址:https://www.cnblogs.com/jpfss/p/10944716.html
原文地址:https://www.cnblogs.com/jpfss/p/10944716.html