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

        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選項雙擊需要進行單步調試的線程

然后選擇Frames Tab選項中調試的線程進行快捷鍵調試即可。

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM