Java Anomaly in Simple Context
<p>I'm encountering a very strange anomaly in the run() method of a thread.</p>

<pre><code>public class project extends JApplet implements KeyListener, MouseListener, MouseMotionListener, ActionListener, Runnable {
  private boolean gameStarted;
  public void init() {
    gameStarted = true;
    new Thread(this).start();
  }
  public void run() {
     while (true) {
        if (gameStarted)
           System.out.print("OK");
     }  
  }
}
</code></pre>

<p>The variable gameStarted is true, but the system does not print anything as a result. This is part of a larger class which is the base class for a game I'm working on. However, this has me completely stumped and I can't understand why this won't work. If instead of gameStarted I put <code>true</code> in the if statement, it does print out OK.</p>

<p>Also note, if I change the run() method to the following, it works exactly as expected given that gameStarted is true:</p>

<pre><code>public void run() {
     while (true) {
        System.out.print(gameStarted);
        if (gameStarted)
           System.out.print("OK");
     }  
  }
</code></pre>
