3

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?

Community
  • 1
  • 1
vish4071
  • 5,135
  • 4
  • 35
  • 65

1 Answers1

9

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.

essa
  • 155
  • 7