Updating object with multiple threads without synchronization java Barcelona nude beach
For single thread applications, synchronization is just an extra speed break.
That is the reason, for recommending Array List over Vector and String Builder over String Buffer for single thread applications (All the methods in Vector and String Buffer are synchronized methods).
Thread deadlock is a critical situation, where two threads are waiting for a shared resource but both of them cannot continue to execute.
In this case, synchronizing the whole method would reduce the performance.
As a solution, using synchronized block is recommended over synchronized methods.
If a thread is executing a synchronized instance method, other threads cannot execute any synchronized instance methods of that object until the current thread leaves from the synchronized method.
However, still other threads have the freedom to execute any non-synchronized methods.