Eclipse and other Java IDEs for debugging parallel code

I am currently working on some parallel code that seems to have several race conditions. I am trying to debug code using my current IDE, Eclipse, but I am not completely satisfied. In particular, there is a race condition for a variable, so without a breakpoint on one of the access methods to it (the one that "receives"), the method of setting the variable does not end, and the variable is null. However, if I set a breakpoint for the access method and hold F8 β€” the default transition button β€” the variable is almost always set to the correct (non-zero) value.

This leads me to ask the following: is it possible that Eclipse is not stopping execution at the breakpoint for all threads fast enough so that I can look at the potential race condition as it appears without a breakpoint, or something else (maybe)?

If this is the case that Eclipse does not pause execution quickly, are there any other IDEs / debuggers for Java that can better handle this? Please note that I am not looking for formal verification tools such as Java Pathfinder. I don’t want to check for race conditions, I want them to unfold in my debugger (if only because it would be interesting to see).

+7
java debugging eclipse concurrency ide
source share
3 answers

This leads me to ask the following: is it possible that Eclipse is not stopping execution at the breakpoint for all threads fast enough so that I can look at the potential race condition as it appears without a breakpoint, or something else (maybe)?

Well, not only this, but the very presence of the debugger changes the environment in such a way that you do not reproduce identical situations that actually arise when your program is executed. Eclipse pauses some threads when they hit a breakpoint, but other threads that don't hit a breakpoint can continue to work and keep changing your data.

Eliminating race conditions using a debugger is quite difficult - you are looking not only for a needle in a haystack, but also a debugger modifies the structure of a haystack.

You can probably talk much better about the code and strategies that you take to handle parallel code. For example, do you protect the general state with locks? How / what are you syncing to? To write to the variable foo , what steps should the threads go through?

+4
source share

By default, Eclipse will not pause other threads if your breakpoint is reached by one thread. However, you can change this behavior in Window > Preferences > Java > Debug > Default suspend policy for new breakpoints => 'Suspend VM' .

+8
source share

Remember that access to a variable / setting is not guaranteed in one step. You probably want to use an atomic object.

And also remember that the value of a variable can be cached. To make sure it is not cached, use volatile.

And if you forget, you can set a breakpoint for the variable. Just click on the left side of the variable declaration, for example, when you create a normal breakpoint.

+1
source share

All Articles