Synchronizing on synchronized collections-> performance issue
<p>Based on the answers below :
It is Still not clear to me: What does the synchronized construct on the concurrentMap do, if anything. i.e. in the case of a concurrentmap, what is the difference if any between synchronized(map) versus non synchronizing. <b><i>I am not interested in the correctness or believed goodness of the solution</i></b>. Just an answer to the question:
Q:What is the difference between synchronizing on a concurrentmap and not synchronizing on the same? Specifically with regard to performance.. will suffice. Nothing more please.<br>
I am only interested in what happens and no supplementary advice.</p>

<p>I have a theoretical question which I am having a bit of a mental problem resolving:
Assume I have a Concurrent Collection class say=>ConcurrentHashMap map;</p>

<p>Assume I have three methods:</p>

<pre><code>method1: synchronized(map){
       doSomethingWithThemap(); //Assume put integers 1.. 1000000
}

method2:doSomethingWithThemap(); //Note it is not synchronized 
method3:doSomethingElseWithThemap(); //Assume put integers 2000000.. 3000000
</code></pre>

<p>Now assume 2 TestCases:</p>

<hr>

<ul>
<li>TestCase1: Spawn two threads A &amp; B. A calls method1 and B calls method3.</li>
<li>TestCase2: Spawn two threads A' &amp; B'.  A' calls method2 and B' calls method3.</li>
</ul>

<p>From a performance point of view I would expect TestCase2 to win, since from what I understand, in TestCase1 B cannot add to the map, albeit concurrent, since the synchronized block will hold the lock on the map, and this is not the case in TestCase2.</p>

<p>My Unit Tests DO NOT validate this hypothesis.</p>

<p>Q: What am I missing here. i.e. Given a synchronized block on a concurrentcollection is performance impacted at all?  </p>
