The first cycle only "appears" to start endlessly. In fact, you start "active waiting", burning 100% of your processor so that your OS or JVM cannot create a context switch and allow another thread to start.
With System.out.println() , on the other hand, I / O is involved, which leads to a somewhat "inactive wait". The OS or JVM can switch contexts and start another thread.
If you run your first program in 10 hours, I'm sure the loop will eventually break
source share