title: Spring MVC Singleton thread safety?
body: <p>I have a singleton Spring bean (default scope). So, one instance will be used by multiple threads. However, I'm a bit confused with regards thread safety, apparently all Spring beans are thread safe if they are stateless, but my bean is not stateless, it has various instance variables which are used by each request/other controllers/classes.</p>
  
  <p>Here is the beginning of my singleton bean:</p>
  
  <pre><code>public class PcrfSimulator {
  
  private final CustomGxSessionIdCacheImpl gxSessionIdCache = new CustomGxSessionIdCacheImpl();
  private final PcrfRecord pcrfRec = new PcrfRecord();
  private final ResponseConditions responseConditions = new ResponseConditions();
  
  public CustomGxSessionIdCacheImpl getGxSessionIdCache() {
      return gxSessionIdCache;
  }
  
  public ArrayList&lt;Rule&gt; getRules() {
      return pcrfRec.getRules();
  }
  </code></pre>
  
  <p>So, the fields above will be accessed by multiple threads - is it enough to mark these fields as volatile, or do I have to mark the methods which access them (there are a lot in not only this class, but other controllers/classes as well) with synchronized and use wait/notify etc?</p>
  
  <p>Many thanks!</p>