Intellij idea debugger
Private void asyncExample() throws InterruptedException, ExecutionExceptionįinal CompletableFuture future = supplyAsync(() -> "F").thenApplyAsync(this::append_oo)
If you're debugging a specific action, you can suspend just one thread and let the rest of the system keep working. If you want to check the state of all threads and see what thread has progressed and what thread might be unnecessarily waiting, you can freeze the entire system at this point and view call frames and stack traces of all threads. The decision is based on the goal of the debugging session. When doing that, pay attention to whether a breakpoint suspends just a thread or the entire application.
INTELLIJ IDEA DEBUGGER CODE
We can insert breakpoints at different points in the code and regardless of the executing thread, see the progress from one code snippet to the next. The execution jumps between frames and makes it harder to understand and follow the code. The flow in an asynchronous application is a major challenge for debugging tools and the developers who use them. Reactive programming is increasingly popular and with the help of many frameworks and libraries out there, developers are writing a lot more asynchronous code. Line breakpoints to suspend the JVM or thread. In this tutorial we try to dive deeper into debugging techniques and assume you are already familiar with the basic concepts such as: This is the point where debugging is so effective. When we debug, we must always compare that information with our expectations, and pay close attention when the code deviates from these expectations. This will dictate how our debugging session should be conducted. In most cases we will also have some initial assumption as to why things are wrong. what is different from the expected behaviour or state. If we're looking for a bug, we need to roughly know what is incorrect, i.e. Before starting a debugging session we must have some knowledge of what we're trying to achieve by it. In fact, the only way to learn from a debug session is to constantly compare the information the debugger shows us with our expectations from the code and how we think it "should" behave.
Last point to remember is that debugging is not a substitute for understanding the code. As we are about to see, this becomes a critical issue in multithreaded environments, when sometimes reproducing a bug depends on a very specific sequence of events. Every breakpoint or log is a possible synchronization point, and stepping obviously changes the timings significantly. The minimal debug tracking overhead in itself may already be enough to change the timing of events and therefore the application behaviour. The timing of execution is also very different when you debug code compared to running it. We will explore a few ways to minimize its impact and sometimes even exploit it. During this tutorial, bear in mind that debugging is an intrusive approach that may affect the outcome of the debugged application. Every evaluation of an expression happens using the same memory of the debugged application, and can modify and potentially corrupt the state. The debug process is part of the runtime and therefore affects it. The IntelliJ IDEA debugger offers a rich experience that helps us to easily debug anything from the simplest code to complex multithreaded applications.īefore we start, a word of caution: debugging is a very powerful tool but it does come with a cost. Finding bugs just happens to be a very common use case for the knowledge we can get from a debug session. The information we get from debugging is useful even when there is no problem with the code. "Debugging" suggests we deal with bugs but this is actually a misnomer.
This is very intuitive and powerful but also may be misleading as most modern applications are multithreaded. As part of that, it gives us the illusion of a sequential flow. It allows us to trace running code and inspect the state and the flow of the execution. It gives us a unique insight into how a program runs and allows us to gain a much deeper understanding of the piece of code we debug. Debugging is one of the most powerful tools in any developer's arsenal.