Six, idea how debug multi-threaded

I. Background

1. recently doing a multi-threaded demand, you may need to start the debug mode is done after the completion of debugging code, the next step is how to get my FBI multithreading in the actual project.

2. Here we use a little off his chestnuts in terms of multithreading following debug.

Second, the code

1. Code (a main thread, a sub-thread)

public class DaemonThread {
    public static void main(String[] args) throws Exception {
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {
                    try {
                        Thread.sleep(10);
                    } catch (Exception e) {

                    }
                    System.out.println(Thread.currentThread().getName() + "i:" + i);
                }
            }
        });
        t1.start();
        for (int i = 0; i < 10; i++) {
            try {
                Thread.sleep(10);
            } catch (Exception e) {

            }
            System.out.println("main" + "i:" + i);
        }
    }
}

2. breakpoint play

3. setting breakpoints (two are shown in FIG set breakpoints)

 

4. This can switch the execution of each thread

5. Results

 

Third, the end of the

1. The above is a summary of how to debug a multi-threaded, and hope a lot of criticism! ! !

Published 122 original articles · won praise 64 · views 50000 +

Guess you like

Origin blog.csdn.net/chenmingxu438521/article/details/103802844