The best idea debug long article? After watching my Buddha


Hello, I’m your Batman.

Recently, I wrote several articles in IntelliJ idea series, and the response was very good. I thought about it, because it’s not about sharing some cracking methods, recommended plug-ins and topics, but it’s really helpful to work and useful to improve work efficiency. The students still have many pain points about using idea, or the posture is not correct and elegant enough. Brother a has always insisted on writing some columns with a certain depth, even if it’s just a tool idea.

Last articleAt the end of the article, I explained that the idea series of this plan came to an end, but I received several hundreds of words of messages and private messages. I felt that some readers really paid attention to it, so I decided to do some more. For the idea series, tools, it’s meaningless to study the principle. Instead, from the user’s point of view, it’s the only purpose to introduce the correct posture and best practices. Using tools to improve efficiency is the only purpose.

Of course, there are also private letters asking me how to set my theme very good? What plug-ins are used? How to develop custom plug-ins? And so on, I don’t think it’s necessary to share it alone, because with Google Baidu, you can find a push-pull, and there are more articles written by big men from all walks of life

This article introduces idea debugging debug, because it’s really important.Whether you can debug, whether you have the awareness of debugging, and whether you understand the skills of debugging are important signs of whether you have started programming.I have published an article about idea debugging in CSDN for a long time, and the response is quite good (it seems that there are many people with pain points)

The best idea debug long article? After watching my Buddha

Today I will “move it over” and make “enhanced” changes to share. I hope you like it.

Outline of this paper

The best idea debug long article? After watching my Buddha

Version Convention

  • IntelliJ IDEA:2020.3.2

Episode: idea has just released its small version 2020.3.2, and the startup diagram has been changed to20th anniversaryFig,IntelliJ idea is 20 years old. The 2-day anniversary is free for developersFeel:

The best idea debug long article? After watching my Buddha


Debug is not a strange concept to it practitioners. It is often used in work, which is not related to junior, intermediate and senior programmers. There are many ways to debug program, such as: output log, add auxiliary variables, split function body, breakpoint debugging, etcbreakpoint debugging –It is the most effective debugging method. To be exact, this article is about using IntelliJ idea breakpoint debugging.

Debug is used to track the running process of the code. When there is an exception in the running process of the program, enabling debug mode can analyze and locate the location of the exception and the change of parameters in the running process. In addition, we can also use debug mode to track the running process of code to learn excellent open source framework.

How important is breakpoint debugging?

it is said thatCode for 5 minutes, debug for 2 hoursFrom this sentence, we can see the importance of debugging. After all, it takes up “most” of your time.

In order to truly reflect its importance, I “quoted classics” and found several senior industry experience bosses to quote their words:

  1. Debugging skills are better than coding skillsMore importantBecause we spend more time debugging than coding and learn more than coding
  2. Debugging skills are very importantexceedLearning English
  3. Programmers who can’t debug,sureNo good software can be produced

I put the key words are bold, its importance can be seen. The boss still thinks so, let alone me? So, read o (∩) carefully_ (laughter)~

What is a breakpoint?

Suddenly asked, is not the head muddled?

The best idea debug long article? After watching my Buddha

If you really want to give a definition of a “thing” that you use every day, you may not be able to explain it clearly for a while. Of course, the main road is very simple. To understand its essence and to be able to use it skillfully is the absolute principle. As a “serious” technical article, this paper naturally needs to first describe the concept of breakpoint in words.

breakpoint: for debuggingdeliberatelyThe place where the program is suspended. It’s an additionalSource code aboveThe particularity ofsign, which can be triggered in debug modeSpecific actions, such as pause execution, print thread stack, evaluate expression value, variable trace, etc. The setting and canceling of breakpoints are managed manually. If not handled manually (deleted), the breakpoints and items will always exist.

If you’ve read the first two articles, you can certainly explain why it always exists in the project. I suggest you go to the,Direct access by elevator

It can be seen that the core meaning of breakpoint is to pause the program, so that you can see the variables, IO, threads and other information of the online text at the moment of pause, so as to have a deeper understanding of the program, find the problem in time and trace the root cause of the error.

Breakpoint parameters

Breakpoints don’t exist in isolation. They can also have parameters to customize different breakpoint behaviors so that they can take effect under different conditions. This parameter is calledBreakpoint parameters

We usually use moreConditional breakpointIt is the most typical application of breakpoint parameters. Of course, in addition to conditional breakpoints, other breakpoints can also be customized. What breakpoint types can be used and customized? Then we will step into the main content of this article and start to enter the more interesting part.

Basic use of breakpoint

No one should not interrupt, even if you are a product manager (Product Manager inexplicably lying gun, manual dog head ~).

The simplest and most direct way to break a point is in which line of code you want to set a breakpointLeftmost window barClick the left mouse button to see a small red dot after completion, which means that the breakpoint is set successfully. Click again to cancel. It looks like this:

The best idea debug long article? After watching my Buddha

Because my idea interface is simple, as far as possible to remove the “button”, so usually I use a lot of shortcut keys to operate the idea, interrupt point is so often done with shortcut keys. Of course, a lot of time also use the mouse, after all, the mouse processing still has its great advantages.

Note: my shortcut is Ctrl + Shift + B, only for your reference

Manage breakpoints

Managing breakpoints includes adding and deleting breakpoints.

For a small number of breakpoints, it is OK to click one by one to delete them. But if you hit a “large number” of breakpoints in the code (for example, when looking at the source code of XXX), it is not realistic to let you find and delete them one by one. After all, you may forget where there are breakpoints. At this time, a management page / window is particularly important. This window is provided in idea. You can open it in a variety of ways

  1. Menu bar mode: Run – > View breakpoints. The disadvantage is that the path is too long and troublesome
  2. Actions mode: double click shift to call up the actions window, and enter view breakpoints to open it
  3. Right click at any breakpoint: select more to open the management window. The drawback is that you have to find at least one breakpoint as a starting point
  4. Debug window: the opening mode will be mentioned below
  5. Shortcut keysThere is no doubt that this is my most recommended way

The best idea debug long article? After watching my Buddha

In this management page, you can modify the breakpointsAddition, deletion and modification

Note: my shortcut is Ctrl + Shift + F8, only for your reference

How to run in debug mode?

Well, isn’t that a little simplistic.

There are many ways to start the debug mode, such as the bug icon button in the toolbar, the left click in the program method entry, the menu bar, the right-click menu bar, and so on

The best idea debug long article? After watching my Buddha

As far as I know, the most common way for many students is to click on the top right corner of the upper toolbarBug IconBecause I don’t have this icon, I won’t show it in the tutorial. Brother a usually uses shortcut keys to start programs 99% of the time, because I think it’s the fastest and most convenient (not necessarily for you).

My shortcut keys for this function are divided into two categories

  1. Run the currently selected entry class in the upper right corner. It has a set of shortcut keys

    1. CTRL + Shift + Alt + Enter: run
    2. CTRL + Shift + Alt + \: debug run
  2. Because a lot of the time you need toNew entranceTo start a program, you may not experience it when doing spring boot project development (there is only one entry), but when doing tutorials and demo, the entry of the program often changes, so it’s impossible to change the boot class every time. The efficiency is too low. For this reason, I set up a new set of shortcut keys

    1. CTRL + Shift + Alt + [: run,Focus of mouseAs an entrance
    2. CTRL + Shift + Alt +]: debug run,Focus of mouseentrance

In addition, if you want to distinguish between run and debug this time, in addition to looking at the bug icon in the upper right corner, it is a better way to see which one is activated in the bottom console window. The advantage of this view is that even if the same application is started many times, you can quickly see which debugs and which runs.
The best idea debug long article? After watching my Buddha

The best idea debug long article? After watching my Buddha

It’s worth mentioning that when running in debug mode, if no breakpoint is activated (for example, you don’t have a breakpoint at all), the effect is the same as that of running mode (but the console window is different, so the location of log output is also different).

Debugging window details

Debugging window is our breakpoint debuggingoperation panel It is very important to skillfully use this panel to improve efficiency and master more skills. Let’s get to know it first

The best idea debug long article? After watching my Buddha

There are many buttons on this operation panel. How proficient you are in debugging is largely determined by your proficiency in operating this panel.

Debug button

The most commonly used row of buttons, entry necessary.

The best idea debug long article? After watching my Buddha

There are 9 buttons in total, which are explained from left to right

The best idea debug long article? After watching my BuddhaShow execution point: return to the active breakpoint. Effect: if your mouse is on another page / category, click it to quickly “return”

The best idea debug long article? After watching my BuddhaStep over: also known as single step debugging, it goes down line by line. If this line is a method, it will not enter it. This button should be the one that is used most often, but it’s not one of them. Therefore, it is suggested to remember your shortcut keys to improve efficiency

The best idea debug long article? After watching my BuddhaStep into: enter the method body. The method here refers to the method defined by you or the method of the third-party library. It will not enter the official method of JDK (such as system. Out. Println () above)

The best idea debug long article? After watching my BuddhaForce step into: you can enter any method, including JDK. It is generally used only when you look at the underlying source code

The best idea debug long article? After watching my BuddhaStep out: it is used together with (force) step into. When you enter into the method body through step into, there are generally two solutions: step out slowly, and the other is step out (recommended)

The best idea debug long article? After watching my BuddhaDrop frame: back to the current methodCall placeAt the same time, the values of all variables in the context return to that time. The prerequisite for this button to be able to click is: the current method has a superior method. If you are in the main method, then the button is gray

The best idea debug long article? After watching my BuddhaRun to cursor: place the cursor where you want the code to stop. This function is too easy to use, greatly ease the dense breakpoints, highly recommended

The best idea debug long article? After watching my BuddhaEvaluate expression calculator: looking at the icon is a calculator, so you can execute it herewhateverLegal expression

The best idea debug long article? After watching my Buddha

The best idea debug long article? After watching my BuddhaTrace current stream chain track the current stream: only when the code stops on the stream statement, this icon will be lit and can be clicked. This is the killer level function of debugging stream provided by idea, which will be explained in detail in the following article

This row of buttons is very important, even the most important. You must master them skillfully, which can greatly improve the efficiency of debugging code, and test them effectively.

Service button

Define the leftmost vertical row as service button to provide service for debugging process.

The best idea debug long article? After watching my Buddha

A total of 10, but they are relatively simple and easy to understand. Again, from top to bottom:

  1. Rerun XXX: close the current program and rerun it
  2. Modify run configuration: as the name suggests, modify the running configuration. The effect of clicking this button is the same as that of clicking the box in the upper right corner:

The best idea debug long article? After watching my Buddha

Click to open the configuration window:

The best idea debug long article? After watching my Buddha

Each runtime configuration is named and unique, isolated from each other. There are many items that can be modified in the running configuration, as follows:

Note: the page of my screenshot may be different from you, because I use the latest version of idea, and this page has been revised in 2020.3

The best idea debug long article? After watching my Buddha

  1. Resume program: resume program. When the breakpoint is activated, the program “stops”. Click this button to restore. The effect is as follows:Jump to the next breakpointIf there is no breakpoint at the end, the operation will be finished. This buttonVery common
  2. Pause program: pause the program. Well, as long as you’re stuck at the breakpoint, the status is pause. At this time, there is a question. Is this button always gray? What’s the use? I’ve seen it on the Internet and it’s almost impossibleno oneCan explain its function, here a elder brother tries to explain to you, with a picture to give you clear, obedient

The best idea debug long article? After watching my Buddha

  1. Stop XXX: no explanation
  2. View breakpoints: open the breakpoint management window. The usage of this window has been explained in detail
  3. Mute breakpoints: this button is very interesting. It makes all breakpoints gray, that is to say, it makes them grayinvalid。 It is a batch operation, and the operation object is all breakpoints, not one. If you don’t want to delete all breakpoints now, but don’t want them to stop you, you can use this button
  4. Get thread dump: get itCurrent threadTo view the status of the current thread. As shown in the figure below:
    The best idea debug long article? After watching my Buddha

    The best idea debug long article? After watching my Buddha

  5. Settings: opens the settings menu. It belongs to advanced use. The effect of each item is explained in the following section

The best idea debug long article? After watching my Buddha

  1. Pin tab: if you can debug the program XXX very frequently, pinning it will help to improve efficiency

Method invocation stack

displayCurrent methodAt the top of the stack.

The best idea debug long article? After watching my Buddha

Note: click the small funnel icon in the upper right corner to display only your own methods instead of class library methods, which is convenient for debugging


In this area, you can view all variable values within the context of the current breakpoint (even if they are not in this class, you can click to view them), including static.

The best idea debug long article? After watching my Buddha

It is worth noting that the variable idea in this area automatically calls itstoString()Method, so if you run normally and only output one sentence of log, debug output multiple sentences, this is probably the case.

Watches variable tracking

Sometimes there are a lot of variables, and only need toFocus onA few variables, you can use watches.

The best idea debug long article? After watching my Buddha

In addition to the above, there are also some very practical functions, such as dynamically changing the variable value set value, jumping to the source code, jumping to source, etc., which are left to your own development and experiment.

Why didn’t the debug window open automatically?

Some students have encountered this situation: the breakpoint is activated (the program is suspended), but the “operation panel” does not come out, how to break it?

Not to say much, just check that your configuration item is checked. In this state, idea is checked by default, so you don’t have to worry about it.

The best idea debug long article? After watching my Buddha

Strange and skillful techniques of breakpoint debugging

Finally, standing at the level of use, I will introduce some very practical “strange and obscene skills” to you. These tips can be used.

Force return (interrupt debug)

Scenario Description: during debugging, when I go to the third step, I find a problem. At this time, I don’t want to finish the follow-up process (for example, because there is a bug in the front, the follow-up process will delete data, etc.). What should I do at this time?

Click, stop program. Yes, I did the same for a long time, and I really achieved my goal. Until I found a more elegant way:Force ReturnThe effect is to force the return value of the method to avoid the subsequent process.

The best idea debug long article? After watching my Buddha

Conditional breakpoint

The activation condition of a specified breakpoint can be called a conditional breakpoint. In general, given a calculation expression under the line breakpoint and the result is true, the breakpoint is activated. This is the most common way. Because there are already cases above, it is omitted here

Multithread debugging

The advantages of multithreaded programs need not be mentioned, but it is well known that it is difficult to debug

public static void main(String[] args) {
    //Three "tokens" in total
    CyclicBarrier cyclicBarrier = new CyclicBarrier(3);

    //Simulation of multiple threads to grab
    for (int i = 0; i < 10; i++) {
        new Thread(() -> {
            try {
                String name = Thread.currentThread().getName();

                System. Out. Println (name + ", ready to grab token");
                System. Out. Println (name + ", already seized");
            } catch (Exception e) {
        }, thread + I). Start();



At this time, if you want to studyawait()Method implementation, the prerequisite is that multiple threads enter, so it needs to holdMultiple threads。 If you just break a common line in await(), the result will look like this:

The best idea debug long article? After watching my Buddha

All threads are in running state, which indicates that this is impossible, because there are only three threads in total. In addition, you have to wait until you finish the others, so this is not at allReal execution scenariosIt is impossible to trace to the await () method to explore its implementation.

In order to simulate this scenario for debugging, the breakpoint blocking condition is set as follows:

The best idea debug long article? After watching my Buddha

Run the program again, and the thread is as follows:

The best idea debug long article? After watching my Buddha

Fast calculation expression

We all know that evaluate expression in the debug panel can calculate the value of an expression / variable, but after all, it’s a little troublesome to pop up a window. In fact, there are more convenient ways:

The best idea debug long article? After watching my Buddha

With the mouse operation, the efficiency is improved exponentially. The operation mode is as follows:Mouse pointer selection expression (idea intelligent automatic selection) + left mouse click。 Of course, if you want to execute a custom expression that doesn’t exist in the code, you have to call up the window.

Stream debugging

The popularity of Java 8 has brought streaming programming into our vision. There are many advantages of using stream programming, but it is hard to read and writeDifficult to debugEspecially the latter.

In order to debug it, we often need to insert other breakpoints and analyze each transformation in the flow. Fortunately, idea provides the “ability” to handle this pain point: when the debugger is in the stream API call chainStop before or withinClick the icon trace current stream chain to show it in a “very good looking” graphical way

The best idea debug long article? After watching my Buddha

Actively throw an exception

Requirement scenario: you have written a global exception component. Now if you want to test its effectiveness, you need to actively throw this exception. The general approach is as follows:

//I actively throw one in the program
throw new NullPointerException();

//Or build an expression
int i = 1/0;

This kind of method has certain code invasiveness, and has to be deleted after use. In fact, idea also provides a more elegant solution:

The best idea debug long article? After watching my Buddha

After mastering the basic skills of idea breakpoint debugging, let’s go to the deep water area of this article: breakpoint type. It’s not very difficult. It’s still a matter of using. But because many students don’t know it, it’s a good material for you to overtake.

Four types of breakpoints

For the interruption point, it is estimated that most students will only click the left mouse in this most basic way. So, when you see this subtitle, you must be confused again. what? What kind of breakpoints are there?

If you just click the mouse on the left side of the code, hit “little red dot”, and then Gaga is dry, turning 720 degrees in the air and rolling backward for three and a half weeks… A player, then sit down and get ready to start.

The best idea debug long article? After watching my Buddha

This posture may help you locate more than 50% of the problems, but what about the other half of the cases? Such as for loop debugging, stream debugging, lambda debugging, exception debugging and so on“A bit of abetting”It’s very difficult to deal with it, or even impossible to deal with it. This is to help usFast positioningThe problem is that different scenes with appropriate breakpoints will get twice the result with half the effort.

As everyone knows, idea provides us developers with special breakpoint types to deal with debugging in different scenarios. Using the right breakpoint type in the corresponding scenario can greatly improve the efficiency of debugging, so as to improve the efficiency of debuggingWhen others work overtime, you get off workEfficiency is time, and time is life.

The best idea debug long article? After watching my Buddha

As shown in the figure, idea divides breakpoints into four types (there are only three types in the screenshot)

  1. Line breakpoint: small red circle in the picture. As the name suggests, set a breakpoint on the specified line of code
  2. Field watchpoint (property breakpoint)Red eyes in the picture. A breakpoint on a class property (static or non static) is used to break the propertyRead and writeActivated when
  3. Method breakpointRed diamond in the picture. The tag is on the line of the method signature and is activated at the entry / exit of the method execution
  4. Exception breakpoint: Little Red lightning. This is a special but useful breakpoint when the program throwsSpecified exceptionThe exception breakpoint is activated when the. Unlike other breakpoints, exception breakpoints are project breakpointsGlobalIt doesn’t need to be typed on a specific line

Now it’s time to bite the hard bone. Come on.

Line breakpoint

The most widely used breakpoint type is usually used in most cases.

The best idea debug long article? After watching my Buddha

From the “tutorial”, we can see that there are many settings for this breakpoint, that is, there are many breakpoint parameters that can be configured. Let’s learn about it.

Breakpoint parameters

Because this is the first one to introduce the type of breakpoint parameters, we will talk about it in detail. In this way, the parameters with the same function need not be described in detail later. Check this screenshot page:

The best idea debug long article? After watching my Buddha

  • EnabledNo explanation. But note: if this item is not checked, the small red dot will not disappear, but will change from solid to solidHollowOf course, this item is not normally used
  • Suspend: as we all know, when a breakpoint is activated, it will block the program to continue running, thus blocking the current thread. But when you find that it’s a check box, are you surprised? What’s the difference

    • If it is not checked, the related activities (such as logging) of this breakpoint are still normalNon blocking processIt’s over
    • If checked:

      • All(default): block all threads in the program
      • Thread: blocking onlyCurrent breakpointThread
        The best idea debug long article? After watching my Buddha

        As shown in the figure above, don’t check suspend: thread 14 and thread 15 are running normally, “unimpeded”
        The best idea debug long article? After watching my Buddha

        As shown in the figure above, check suspend all: at the breakpoint,All threadsIt’s all blocked. Wait for me.

The best idea debug long article? After watching my Buddha

As shown in the figure above, the thread that checks suspend thread: method1 is blocked, but it does not affect another thread to call method2.

Just think, since “suspend thread” is less influential, why does idea help you choose all instead of thread by default? The reason is like this: the purpose of debugging is to make the program “slow down”, and it is better to stop to analyze the problem. Otherwise, if other threads continue to execute, this request may change this data and that data, which increases uncontrollability. The increase of uncertainty greatly increases the difficulty of debugging and positioning, so the last “synchronization lock” is easy to worry about, so it is reasonable to select suspend all by default.

Note: most of the time, we need to use the local connection test environment break point for remote debugging, if in this case, we strongly recommend that you use thread mode, otherwise you understand

  • Condition: the condition under which the breakpoint is activated. You can write expressions here, only expressions returntrueThis breakpoint is activated only when the

    • Strictly speaking, conditional breakpoints do not belong to a breakpoint type. They are determined by breakpoint parameters. Many types of breakpoints can be conditional

The best idea debug long article? After watching my Buddha

  • LogIt has three options: check box. That is to say, you can select all or none. By default, none is selected

    • Breakpoint hit message: output prompt log when breakpoint is activated
    • Stack track: output program call stack information when breakpoint is activated
    • Evaluate and log: select the value to output the calculation expression. You can select the currently available variables, such as the main function in this example, the input parameter args, etc
  • remove once hit: the breakpoint will be removed immediately after it is activated once, that is, the so-called temporary line breakpoint. Let’s introduce it

And the condition on the far right of the window:

The best idea debug long article? After watching my Buddha

The name means a series of filters: filter instance, filter class, filter caller, etc. generally, these filters can hardly be used (at least I haven’t used them yet), so I’ll take them all at once.

Usage scenarios

Line breakpoints are generally used together with single step debugging, especially when looking at the framework source code and positioning basic problems. It is a breakpoint type that needs to be mastered most, and there is no discussion.

Temporary line breakpoint

It is also a kind of line breakpoint, but the parameters are different. Because it’s special, it’s just picked out and said. Create a normal line breakpoint, and thenRemove once hitIf the check box is checked, it is a temporary line breakpoint. The effect is as follows:

This breakpoint type is rarely used in actual scenarios.

Property breakpoint field watchpoint

This kind of breakpoint is hit on the property, member property and static property. It’s not a little red dot, it’s a red “little eye.”.

The best idea debug long article? After watching my Buddha

Breakpoint parameters

The best idea debug long article? After watching my Buddha

As shown in the figure, this breakpoint typespecificThere are two watch parameters. The meaning of the two optional values is:

  • File access: when reading this property (regardless of writing)
  • File mapping: when writing this property (regardless of reading)

Usage scenarios

When you want to know who is assigned the value of the XXX attribute, because the program is too complex to know where to start tracking the breakpoint, it is very convenient to use the breakpoint of the attribute type at this time.

Method breakpoint

The breakpoint must be on the line of the method signature, and the color shape is a small red diamond.

The best idea debug long article? After watching my Buddha

Breakpoint parameters

The best idea debug long article? After watching my Buddha

Watch has three optional values:

  • Simulated: simulated. Function: improve debugging performance, so it is used by default. Official advice: only in debugging remote code or in native method orIn classIt is recommended to disable this option only when a breakpoint is set
  • Method entry: activate breakpoint when entering method
  • Method exit: activate breakpoint when leaving method

If both entry and exit are checked, the breakpoint will be activated after entering and before going out

Usage scenarios

For this breakpoint type, you may say it’s useless. After all, you can achieve the same effect by typing a line breakpoint at the beginning and end of the method. There’s no need to create a separate type.

In fact, it isAssassin’s MaceThe use scenario is to type this type of breakpoint in theInterface methodSo, no matter which implementation class method is invoked, it will activate breakpoints, is it particularly awesome?

Exception breakpoint

It’s small, but it doesn’t mean it doesn’t matter. In my understanding, it is relatively small, maybe most students don’t know how to hit an abnormal breakpoint, because it can’t be easily done with a mouse click.

The above describes the exception breakpoint, which is aGlobal breakpoint typeTherefore, you can’t directly click in the code, you can only add it in the management window:

The best idea debug long article? After watching my Buddha

Compared with other breakpoint types, there are at least the following differences:

  1. Breakpoints can only be created through breakpoint management window, not by mouse click
  2. After creation, there will be no display in the code bar (no small red icon), and the small red lightning will not appear until it is activated
  3. Exception breakpoints act globally: in this case, nullpointexception is thrown anywhere to activate this breakpoint

Breakpoint parameters

The best idea debug long article? After watching my Buddha

Notification has two optional values:

  • Catch exception: the breakpoint will only be activated if you try to catch the exception yourself
  • Uncatch exception: breakpoints are only activated when you don’t try catch yourself

By default, both will be checked, that is to say, breakpoints will be activated whenever this exception occurs.

Usage scenarios

Once you know the function and trigger conditions of the exception breakpoint, you can use the scenario. For example, when your program throws an exception, but for a while and a half you don’t know which line of code caused it, this can be achieved by adding an exception breakpointQuickProblem orientation.

Comparison of four breakpoint icons

Each breakpoint type has its own corresponding icon and different states. I have a comparison chart from the official website, which sums up very well. Here I share it with you

The best idea debug long article? After watching my Buddha

Remote debugging (remote debug)

Nowadays, most microservices are based on microservice architecture. Each microservice usually has more than n upstream / downstream dependencies, which makes debugging very difficult. After all, it is almost impossible for you to enable all the dependencies locally and debug them with idea. Therefore, remote debugging is coming. It is a sharp tool for debugging distributed systems.

Remote debugging: as the name suggests, use local idea to debug remote code (generally in QA environment, online environment can’t open debugging port). So how to turn on remote debugging?

Opening steps

There are only two steps to start remote debugging

Step 1: let the remote deployed application support remote debugging, that is, expose the remote debugging port。 The method is to add the corresponding JVM parameters when the application starts, and the parameters are different for different JDK versions

  • JDK 9+:-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:${debug_port}
  • JDK 5-8:-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=${debug_port}
  • JDK 4:-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=${debug_port}
  • JDK 3-:-Xnoagent -Djava.compiler=NONE -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=${debug_port}

Step 2: create a remote running configuration with idea, and fill in the remote host’s IP + exposed debugging port。 The operation path is:Edit Configurations -> Add New Configuration ->

The best idea debug long article? After watching my Buddha

Everything is ready. Click debug to run. You can see the following words in the console to prove that you have successfully linked:

The best idea debug long article? After watching my Buddha

It’s worth noting that when debugging remotely, make sure you have both local and remote codeAs like as two peasTo achieve the best results.

How to start remote debugging in traditional Tomcat?

If you are a spring boot application, you can add the JVM parameter to jar – jar. What if you want to deploy it in the traditional Tomcat way? This is the time to find the traditional Tomcat startup



PRGDIR=`dirname "$PRG"`


exec "$PRGDIR"/"$EXECUTABLE" start "[email protected]"

In order to add our JVM parameters, we just need toexec xxxJust add a variable value before (take jdk8 as an example)

JPDA_ OPTS='-agentlib:jdwp=transport=dt_ Socket, server = y, suspend = n, address = specific port number "

Note: the key name must be JPDA_ OPTS。

You may be curious to ask: why add a JPDA_ What about the opts parameter? I haven’t seen you eitherexec xxxUse it, in fact, it is not. Let’s explain it briefly.

execThe variable $executable is referenced during execution, which representscatalina.shThis file contains a large number of variable judgment scripts, including those responsible for JPDA_ Opts explains:


if [ "$1" = "jpda" ] ; then
  if [ -z "$JPDA_TRANSPORT" ]; then
  if [ -z "$JPDA_ADDRESS" ]; then
  if [ -z "$JPDA_SUSPEND" ]; then
  if [ -z "$JPDA_OPTS" ]; then

For more knowledge about the JVM debugging platform JPDA, you can use Google Baidu to learn

How to start remote debugging for embedded Tomcat?

Isn’t this the spring boot application form? So, how to open it? No more nonsense~


One of the biggest differences between people and animals is that people can use tools and are good at using them. When tools are created, the mission is to improve efficiency. After all, we can’t write Java programs with Notepad.

IntelliJ idea as the most popular JVM platform IDE, we should try our best to find out its utility. As an integrated development environment, many functions can be done in one stop, and many data can be got through in one platform. For example, idea’s rest interface debugging, database mapping, shell terminal and so on are more than enough to cope with normal development. It is recommended to use them. After all, the more software you start, the more computer card you get.

Using idea and being able to use idea are two levels. Besides the code itself, the most commonly used development tools are also worth thinking about. The road to simplicity, easy to know, difficult to do, unity of knowledge and practice, success!

Thinking questions of this paper

Special column of this article:IDEA, you can get all the content by replying to the column name in the backgroundhttps://www.yourbatman.cnIncluded.

After reading it, you don’t necessarily understand it。 Here are three questions at the end of the article

  1. Can breakpoints be hit on classes?
  2. What kinds of breakpoints can idea set? What are the scenes?
  3. How to debug the application of test environment with idea debug?

Recommended reading

The best idea debug long article? After watching my Buddha

System. Out. Println ("like it!");
print_ R ('pay attention to the Utopia of bat '!';
var_ Dump ('private chat a: fsx1056342982 ');
Console.log ("like it!");
Nslog (@ "focus on [bat's Utopia]!");
Print ("private chat a: fsx1056342982");
Echo ("like it!");
Cout < "focus on [bat's Utopia]!"<< endl;
Printf ("private chat a: fsx1056342982");
Console. Writeline ("like it!");
FMT. Println ("focus on the Utopia of bat]");
Response. Write ("private chat a: fsx1056342982");
Alert ("like it!");

Your Batman: Spring Framework open source contributor, Java Architect, domain expert. The article does not have the title party, does not appeal to the public, each article forms the series to goSystematicTo break through a knowledge point, each series may beBest / unique in the whole network。 Pay attention to the cultivation of basic skills, the bottom foundation determines the superstructure. Existing idea series, spring n multi series, bean validation series, date time series… Pay attention to free access

The best idea debug long article? After watching my Buddha