volatile vs threadLocal in java
<p>Lets take SimpleDateFormat as an example since it is not thread safe.</p>

<p>I could allow each thread to have its own copy of SimpleDateFormat using threadLocal like this:</p>

<pre><code> private static final ThreadLocal&lt;SimpleDateFormat&gt; formatter = new ThreadLocal&lt;SimpleDateFormat&gt;(){
    @Override
    protected SimpleDateFormat initialValue()
    {
        return new SimpleDateFormat("yyyyMMdd HHmm");
    }
};
</code></pre>

<p>But the volatile keyword guarantees that a thread will have the most recent copy of the variable. So could i not do this instead:</p>

<pre><code>volatile SimpleDateFormat myformatter;
</code></pre>

<p>and achieve the same thread safety ?</p>