Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the debugging skills of IntelliJ IDEA?

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

IntelliJ IDEA debugging skills, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

Everyone have a good weekend, today to share the advanced debugging skills of IntelliJ IDEA, to see how coquettish, it is really much better than Eclipse!

Conditional breakpoint

This technique is often used in loops, such as wanting the breakpoint to stop at a specific value while traversing a large List.

Referring to the figure above, at the location of the breakpoint, right-click the little red dot next to the breakpoint, and an interface will come out. Fill in the breakpoint condition here in Condition, so that when debugging, it will automatically stop at the location of iTunes 10.

Second, go back to the previous step.

This technique is most suitable for the scene of particularly complex methods. It is not easy to run, accidentally shake your hand, and the breakpoint is over. I want to look back at the value of the variable just now. If I don't know the skill, I can only run again.

Referring to the figure above, the method1 method calls method2, and the location of the current breakpoint is jroom100. After clicking the Drop Frame icon at the location of the red arrow in the image above, time passes.

Back to the time when method1 was first called, the variable I became 99. Is that all right, guys? is it very 6:)

Note: curiosity is the ladder of human progress, if you want to know why this function is called Drop Frame, rather than something like Back To Previous, you can flip through JVM books, JVM internal stack frame as a unit to save the running state of the thread, drop frame is to throw away the current stack frame, so that the current "pointer" position, naturally to the position of the previous frame.

Third, multi-thread debugging

When multithreading runs at the same time, who executes first and who executes later depends on the mood of CPU and cannot control the sequence. There may be no problem when running, but it is troublesome to debug. The most obvious thing is that the breakpoint jumps randomly, stopping this thread for a while and stopping another thread for a while, such as the following figure:

If you want the next breakpoint to be the second verse, you may be disappointed:

If you want a thread to do as it pleases when debugging, and let it stop on which thread it stops, you can right-click on the little red dot of the three breakpoints in the figure.

That is, Suspend hangs on a per-thread basis, not on an All basis. After setting all three breakpoints like this, try again.

Notice the position of the red box in the image above. When the breakpoint stops, the drop-down box can see each thread. (note: it is a good habit to give a thread an easily recognizable name! ), we can choose the thread "birds in the sky"

The breakpoint stops at the second poem as desired. In addition, if you want to learn more skills, you can follow the Wechat official account: Java technology stack, reply: idea in the background, and get N pieces of IDEA practical information that I have sorted out.

IV. Remote debugging

This is also a sharp weapon to install B, this machine does not need to start the project, as long as you have the source code, you can debug the code on the server directly and remotely. The opening posture is as follows:

4.1 when the project starts, allow remote debugging first

Java-server-Xms512m-Xmx512m-Xdebug-Xnoagent-Djava.compiler=NONE-Xrunjdwp:transport=dt\ _ socket,server=y,suspend=n,address=9081-Djava.ext.dirs=. ${main\ _ class}

What works is

-Xdebug-Xnoagent-Djava.compiler=NONE-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9081

Note: technically speaking, remote debugging is to establish scoket communication between the local machine and the remote, so the port should not conflict, and the local machine should allow access to the remote port. In addition, this parameter should be placed before-jar or ${main_class}.

4.2 setting up remote debugging in idea

Then you can debug it.

The premise is that the local machine has the source code of the project, make a breakpoint where needed, and then try to access a remote url, and the breakpoint will stop.

Fifth, temporarily execute the expression / modify the running value of the variable

When debugging, you can execute some expressions temporarily, refer to the following figure: click any one of these two icons

After clicking the + sign, you can enter an expression in a new input box, such as iDiver5.

Then go back to the car, and you can see the result immediately.

Of course, if you want to dynamically change the value of a variable during debugging, it is also easy to right-click on the variable and select Set Value. Everyone knows the rest.

Have you mastered the debugging skills of IntelliJ IDEA? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 304

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report