Reputation: 5277
I found this link on SO:
Code not working when running normally, but working in debug (eclipse)
and on seeing the answers, added a Thread.sleep(0)
inside my while loop and it works.
The question is "why?". Also, is this problem specific to Eclipse
?
Upvotes: 3
Views: 7045
Reputation: 155
It definitely is not specific to Eclipse. It's a threading issue and can happen in any program using threads that rely on each other. Debug makes the timing issue go away because you are essentially performing a sleep by slowing everything down to walk the code.
If you run debug multiple times with no stops you might find that your failure shows up in a few of the runs.
Making a thread sleep gives the other threads time to "catch up" and complete whatever task the sleeping thread is waiting on.
Upvotes: 9