Do operations on ThreadLocal have to be synchronized?
<p>Here is the code I've stumbled across:</p>

<pre><code>class TransactionContextHolder {

private static final ThreadLocal&lt;TransactionContext&gt; currentTransactionContext = new NamedInheritableThreadLocal&lt;TransactionContext&gt;(
    "Test Transaction Context");


static TransactionContext getCurrentTransactionContext() {
    return currentTransactionContext.get();
}

static void setCurrentTransactionContext(TransactionContext transactionContext) {
    currentTransactionContext.set(transactionContext);
}

static TransactionContext removeCurrentTransactionContext() {
    synchronized (currentTransactionContext) {
        TransactionContext transactionContext = currentTransactionContext.get();
        currentTransactionContext.remove();
        return transactionContext;
    }
}
</code></pre>

<p>}</p>

<p>The <strong>currentTransactionContext</strong> field is of type ThreadLocal and it is the only field in the class.</p>

<p>It seems to me that synchronization is not needed here because value stored in ThreadLocal is associated with particular thread and thus it's not a shared state. In addition I think it impacts performance as currentTransactionContext itself is shared and only one thread is allowed to enter the block while many can do it in parallel without impacting correctness.</p>

<p>Is the synchronization needed here?</p>