title: Is AtomicBoolean needed to create a cancellable thread?
body: <p>I often use the following pattern to create a cancellable thread:</p>
  
  <pre><code>public class CounterLoop implements Runnable {
  
      private volatile AtomicBoolean cancelPending = new AtomicBoolean(false);
  
      @Override
      public void run() {
          while (!cancelPending.get()) {
              //count
          }
      }
  
      public void cancel() {
          cancelPending.set(true);
      }
  }
  </code></pre>
  
  <p>But I'm not sure that cancelPending MUST be a AtomicBoolean. Can we just use a normal boolean in this case?</p>