Conditional breakpoint

Likewise, we can use the value of Thread.currentThread().name to configure a breakpoint that will only affect a given coroutine. This will be particularly useful in two scenarios: whenever you have a group of coroutines created in a loop but are interested in only one, or when you want to set the breakpoint in a piece of code that can be called from any part of the application but you are interested in a specific coroutine.

This can be easily achieved by doing a right-click in the breakpoint indicator and setting a condition based on the name of the thread:

In this case, we set the condition to Thread.currentThread().name.contains("main#2"), in the line where the year is obtained. So the breakpoint will only happen for the @main#2 coroutine.

Get used to having the watch for the name of the thread always set and keep an eye on it when debugging. When you have more than a few coroutines, you need to keep the one you are debugging present. Likewise, consider setting conditional breakpoints so that you target a reduced scope when doing analysis.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.45.5