This article outlines techniques to increase the concurrency of your code while maintaining its correctness. The first step to increasing concurrency is to avoid unnecessary synchronization. The Java language provides synchronization to allow multiple threads of execution to access the same objects safely. Adding unneeded synchronization is as bad as omitting necessary synchronization. Sometimes programmers, in search of thread-safe code, synchronize too many methods.
Excess synchronization can lead to code that deadlocks or code that runs slowly.
One goal of your software is to run efficiently, without deadlocks. Because of the way the synchronized keyword is implemented, the result is often unnecessary synchronization and less concurrency. This class is certainly thread safe. Each method must be declared synchronized in order to ensure the arrays are not corrupted by multiple threads accessing this object concurrently. The same is true of method3 and method4 .