Java synchronized Modifier

Synchronized Method Execution with the synchronized Modifier

Care is required when manipulating shared data in a multithreaded environment. This is because inconsistencies can occur if multiple threads process shared data at the same time.

In such cases, specifying the synchronized modifier prevents the method from being called simultaneously by multiple threads. Even if calls occur almost at the same time, the processing of the caller that arrived first is prioritized, and the later caller waits until the preceding processing finishes. This is called synchronized execution.

public class ModSynchronized {
    synchronized void process() { ... }
}