title: Using synchronized in static variable
body: <p>I have a static Map</p>
  
  <pre><code>private static Map&lt;String, Car&gt; cars = new HashMap&lt;~&gt;() //Map holding car objects
  </code></pre>
  
  <p>I use the variable inside a method like </p>
  
  <pre><code>private static String getCar(String name){
      return cars.get(name);
  }
  </code></pre>
  
  <p>So, if I want to put lock on cars, is it fine to do like below for thread safety. </p>
  
  <pre><code>private static void xyz() {
      synchronized(cars) {
          Car c = getCar("abc");
          c.setColor("Green");
      }
  }
  </code></pre>
  
  <p>Any Suggestions?</p>