Used to have a lot of thread development, multithreading development is a little bit of experience, but the beginning of multithreading development, encountered many walls. But in a sense, a good tool always gets the best of it. The tool I use is eclipse, in the development of multithreading, its debug mode is able to directly simulate the multithreaded environment, there are a lot of data online, but most of them are not very full. I hope I can record some of my experience, I hope to help also for multi-threaded development and tangled friends.
First write a simple multithreaded test case:
Package com.wxw.debug;
Publicclass Testmain extends Thread {
@Override
Publicvoid Run () {
System.out.println ("Hello World");
}
Publicstaticvoid Main (string[] args) {
Testmain T1 = new Testmain ();
Testmain t2 = new Testmain ();
T1.start ();
T2.start ();
}
}
This piece of code, the console prints out two lines
Hello World
Next, you'll demonstrate how to use the debug mode for step-by-step execution, and then gradually apply the knowledge extension
Location of breakpoints
Here is a point to note that the location of the breakpoint must be correct, run method or run after the call method, otherwise, the program ran out, debug mode is also only a main thread in the run, well, directly to see the results.