Breakpoint "concurrency" in Intellij

93 views Asked by At

Lets say I have a class that initiates two threads Thread_A and Thread_B, each doing some calculations and ocassionally using a subroutine of my the class. (don't worry about data sharing, lets say it's a log line or imagine the subroutine is a method in a Java library) I want to know if there is a way of conditioning a breakpoint inside this subroutine to the subroutine having been called from say thread_A, but not B, or say a certain breakpoint having been hit prior to this breakpoint.

Obviously I can always go tho the frames tab in the debug window and see the caller thread, but it is tedious. It might be the case that thread_A accesses the subroutine much less often than thread_B. I don't want to have to see all the breakpoints which are initiated by Thread_B.

The way I currently do it, is setting up global flag variables and manipulating them just before calling the routine. I then have my breakpoint's condition depened on the flag variable. However that is probably not very thread-safe and not very clean.

What is the correct way of doing this? Out of curisoity, is there any other IDE for any other language that does this?

1

There are 1 answers

3
André R. On BEST ANSWER

is the code that spwaned the threads your's ? if so you could set unique names on the threads and use those names to distinguish your threads when using breakpoint conditions.

e.g.

//spwaning the thread
Thread threadA=...
threadA.setName("thread-A");

// IntelliJ
Condition : Thread.currentThread().getName().equals("thread-A")