'Where will we use static syncronization(Java) [duplicate]

static synchronized method locks in the class object and the synchronized method locks the current instance of an object. I am not able to relate to any real-world examples and cant clearly distinguish the difference between them. So if possible give me some examples that I can relate to concept.



Solution 1:[1]

Let's look at Java's Thread class. It offers self explanatory examples.

Synchronized static method - single JVM wide id generator

private static int threadInitNumber;
private static synchronized int nextThreadNum() {
    return threadInitNumber++;
}

Synchronized instance method - lock each thread instance:

public synchronized void start() {
  ...
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Delta George