java
主页 > 软件编程 > java >

idea中断点类型之All和Thread的区别

2022-03-17 | 秩名 | 点击:

All模式

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

public class ThreadAndAllBreakApplication {

 

    public static void main(String[] args) {

        ThreadTest thread1 = new ThreadTest();

        thread1.setName("线程A");

        thread1.start();

        ThreadTest thread2 = new ThreadTest();

        thread2.setName("线程B");

        thread2.start();

        ThreadTest thread3 = new ThreadTest();

        thread3.setName("线程C");

        thread3.start();

    }

}

class ThreadTest extends Thread {

    @Override

    public void run() {

        System.out.println(Thread.currentThread().getName() + ": 1");

        try {

            long millis = RandomUtil.randomLong(100, 500);

            System.out.println(Thread.currentThread().getName() + "睡眠: " + millis);

            Thread.sleep(millis);

        } catch (InterruptedException e) {

            e.printStackTrace();

        }

        System.out.println(Thread.currentThread().getName() + ": 2");

        System.out.println(Thread.currentThread().getName() + ": 3");

        System.out.println(Thread.currentThread().getName() + ": 设置断点的前一行代码"); // 当前行设置断点

        System.out.println(Thread.currentThread().getName() + ": 4");

        System.out.println(Thread.currentThread().getName() + ": end");

线程A: 1
线程C: 1
线程B: 1
线程C睡眠: 283
线程A睡眠: 340
线程B睡眠: 127
线程B: 2
线程B: 3
线程B: 设置断点的前一行代码 // B来到了这里,此时其他线程A、B在原地等待,即A、B都在睡眠。
线程A: 2 // A之前执行到睡眠,现在执行2
线程A: 3
线程A: 设置断点的前一行代码 // A来到了这里,此时其他线程B、C在原地等待
线程C: 2 // c之前执行到睡眠,现在执行2
线程C: 3
线程A: 4
线程B: 4
线程A: end
线程C: 设置断点的前一行代码 // C来到了这里,如果不放行断点,B一直也不会输出end,会在原地等待(这里证明了当某个线程被All断点阻塞后,其他线程会在原地等待)
线程B: end
线程C: 4
线程C: end

Thread模式

所有的线程都会运行到断点处然后阻塞

在这里插入图片描述

原文链接:https://blog.csdn.net/Yal_insist/article/details/123522423
相关文章
最新更新