1. 程式人生 > >IDEA多線程下多個線程切換斷點運行調試的技巧

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

需要 hash log name www. init col package src

多線程調試設置可以參考: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選項中調試的線程進行快捷鍵調試即可。

技術分享

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