title: Thread safety issue with SimpleDateFormat
body: <p>I got the following piece of code from a programmers test</p>
  
  <pre><code>private String formatDate(Date date)
  {
    String result = "";
    //….
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    result = sdf.format(date);
    //…
    return result;
  }
  </code></pre>
  
  <p>with the additional information that several threads are using the method at once. Are there any problems with this?</p>
  
  <p>My answer is that no, it should be fine (assuming that nothing else is going on in the //... parts).</p>
  
  <p>My motivation is that no global or class data structures are used. The date is passed from each tread as a parameter and inside the method only local variables and local objects are being used. Thus, each thread will get and use it's own object instance of the SimpleDateFormat class.</p>
  
  <p>However, this was not the "correct" answer in the test. The "correct" answer is that the class SimpleDateFormat isn't thread safe and that the access to that object therefore needs to be synchronized.</p>
  
  <p>So, am I or the solution correct?</p>