title: Java: naming conventions for thread safety?
body: <p>Imagine I have this class:</p>
  
  <pre><code>class Notifier {
      public Listener listener;
  
      public void notify() {
          if (listener != null) {
              listener.stuffHappens();
          }
      }
  }
  </code></pre>
  
  <p>This code is incorrect in the case <code>listener</code> can be changed from another thread.  Let's fix it:</p>
  
  <pre><code>class Notifier {
      public volatile Listener listener;
  
      public void notify() {
          Listener l = listener;
          if (l != null) {
              l.stuffHappens();
          }
      }
  }
  </code></pre>
  
  <p>The code is correct now, but the <code>notify()</code> method looks weird in isolation.  Imagine a larger class with a mix of volatile and regular fields used in the same method and you'll get the picture.</p>
  
  <p>My first impulse is to name the variable <code>volatileListener</code>---assuming it's private and there's a <code>setListener()</code> of course, but I imagine a "hungarian notation is evil" knee-jerk reaction from many people.</p>
  
  <p>So, are there established practices/conventions?  Or maybe there are some patterns allowing to systematically avoid such situations.  What do you do when writing heavily multi-threaded code?</p>