IDEA多線程下多個線程切換斷點運行調試的技巧

多線程調試設置能夠參考:http://www.cnblogs.com/leodaxin/p/7710630.htmlhtml

 

1 斷點設置如圖:java

 

 

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

        new Thread("Thread1-Name") {
            public void run() {
                System.out.println("Thread1-Name Start");
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                map.put(7, 77);//斷點位置 1
                System.out.println(map);
            }

        }.start();
        new Thread("Thread2-Name") {

            public void run() {
                try {
                    System.out.println("Thread2-Name Start");
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                map.put(3, 33);// 斷點位置2
                System.out.println(map);
            }

        }.start();


        // 斷點位置 3
        System.out.println("Thread-Main-Name Start");
        System.out.println("Thread-Main-Name Start");
        System.out.println("Thread-Main-Name Start");


        Thread.sleep(500000);

    }
}

 

3:啓動debug,咱們能夠在Threads Tab選項雙擊須要進行單步調試的線程oop

而後選擇Frames Tab選項中調試的線程進行快捷鍵調試便可。測試

 

相關文章
相關標籤/搜索