title: Java Synchronization when firing events
body: <p>I have a class like this (irrelevant code removed):</p>
  
  <pre><code>public final class Card {
  
      private boolean important;
  
      public boolean isImportant() {
          return important;
      }
  
      public void setImportant(boolean isImportant) {
          this.important = isImportant;
          fireIsImportantChangedEvent(isImportant);
      }
  
      private EventListenerList listenerList = new EventListenerList();
  
      private void fireIsImportantChangedEvent(boolean newValue) {
          for (CardListener listener : listenerList.getListeners(CardListener.class)) {
              listener.isImportantChanged(new CardEvent&lt;Boolean&gt;(this, newValue));
          }
      }
  }
  </code></pre>
  
  <p>I'm trying to make this class thread safe and am not sure whether I need to synchronize any methods accessing important ( <code>public synchronized boolean isImportant() { ... }</code> and <code>public synchronized void setImportant(boolean isImportant) { ... }</code> ) or just declare important volatile ( <code>private volatile boolean important;</code> ).  It's my understanding that volatile would work if <code>setImportant()</code> didn't fire an event (if it just did <code>this.important = isImportant</code>) but will volatile still work if I do fire this event?</p>