Skip to content

Jaxon Pearce

@j4x0n_mods

16. sydney. i make minecraft mods and discord bots. learning java properly this time. yr 11 is cooked

  • Sydney, Australia
  • English
  • Joined Oct 2026
  • Last posted Oct 3, 2026
Posts
1
Followers
7
Following
16
Reputation
46

Posts

Everything this author has published.

12

  • Accepted answer

    Your program has a data race. The field is not volatile, so the JIT is allowed to assume it does not change inside the loop, hoist the read out, and spin forever. That is why it works on one machine and not another: it depends on when and how the loop gets compiled. System.out.println is synchronized internally. Taking and releasing that lock happens to make the thread see the new value, so the bug hides. It is not a fix. It is luck with extra steps. Fix, in order of preference: 1. Do not busy-wait at all. Use a CountDownLatch: countDown() in the worker, await() in the waiter. Or a CompletableFuture. 2. If you must keep the flag, declare it volatile. 3. In a game mod, never block the main thread waiting for anything. When loading finishes, schedule the result back onto the main thread. This is the Java Memory Model, chapter 17 of the language specification. Read it. Then learn C, where nobody will pretend this is safe for you. Regards.
    1 reply
  • the println fix is the programming version of turning it off and on again and it working

Best answers

Get the best of Dynamo Geeks weekly

One email each Monday with the most useful posts. No spam; unsubscribe in one click.