Is it necessary to synchronize a factory method that returns a new instance of a class in java
<p>Today i was asked to write up a factory to get a new instance of a class.
I did this quite easily.</p>

<p>One of my all knowing colleagues looked at my code and told me to synchronize the method that does this.</p>

<p>I asked him why and he replied that is the right thing to do. (offered no explanation when asked) I did not do it as i believe since i'm not manipulating the state of the object, i don't have to synchronize it.</p>

<p>I just want to clarify whether i was right. If i was wrong, can someone explain why it is necessary to synchronize.</p>

<p>eg</p>

<pre><code>private static Map&lt;String, IProduct&gt; products = new HashMap&lt;String, IProduct&gt;();

public IProduct getInstance(code){
   return products.get(code).create();
}
</code></pre>

<p><strong>Edit based on comments :</strong></p>

<ul>
<li>I can't give the full code as I don't have access to it now. I will do it when I get back to work.</li>
<li>products is a <code>Map&lt;String, IProduct&gt;</code></li>
<li><code>create()</code> is a method on the class implementing <code>IProduct</code>. This method just returns a new instance of the implementing class.</li>
<li>the instance put into the static map is only to be used to 'new' up an instance of <code>Product</code>.</li>
</ul>