title: Synchronization, When to or not to use?
body: <p>I have started learning concurrency and threads in Java. I know the basics of synchronized (i.e. what it does). Conceptually I understand that it provides mutually exclusive access to a shared resource with multiple threads in Java. But when faced with an example like the one below I am confused about whether it is a good idea to have it synchronized. I know that critical sections of the code should be synchronized and this keyword should not be overused or it effects the performance.</p>
  
  <pre><code>public static synchronized List&lt;AClass&gt; sortA(AClass[] aArray) 
  {
      List&lt;AClass&gt; aObj = getList(aArray);
  
      Collections.sort(aObj, new AComparator());
  
      return aObj;
  }
  
  public static synchronized List&lt;AClass&gt; getList(AClass[] anArray) 
  {
      //It converts an array to a list and returns
  }
  </code></pre>