I have a method that I was
testing the performance of that can be called about 500,000 times a second from within my testing
servlet. If the code is synchronized it runs slightly slower, say 1.5 seconds(I don't recall the percentage). However, I wanted to see how synchronization affected performance when I had 5 simultaneous servlets accessing the same method (each servlet gets the same instance variable).
Running the unsynchronized code on 5 simultaneous servlets on a windows box took about 5 seconds. I would have expected hte unsynchronized code not to not execute as if each servlet was performing sequentially.
The synchronized code slowed down to about 30 seconds for the 5 pages too complete. I am surprised that the worse case for the multithreaded test wouldn't just be 5 threads times 1.5 seconds = 9 seconds.
Can anyone shed any light on this?