title: How to maintain mutable state in a Java Singleton
body: <p>I have a Singelton in Java (in an OSGi Service) and want to maintain some state in it (a counter).</p>
  
  <p>Should this variable be static? or synchronized? or both?</p>
  
  <p>Or should i wrap the actions in a syncronized method? (would this be any different than just making the var syncronized?)</p>
  
  <p>I want consumers of the service actions to increment this counter.</p>
  
  <pre><code>public MyServiceImpl implements MyService {
      private int count = 0; // static? syncronized?
  
      public String helloWorld() { count++; return "Hello World"; }
      public int getHelloCount() { return count; }
  }
  </code></pre>
  
  <p>Update: How would I so something like a Map or a List? Is it preferred to use Atomic versions of these too? Or is Synchronized better for this?</p>