Before I answer you question, note that a void method can’t return an ArrayList.
And to the question: They differ in the lock they acquire.
In this case, the first one is an implicit lock on “this”. It’s a way to write
public void getPlayers() {
synchronized (this) {
return list;
}
}
Except that it is a method modifier.
In the second example, you explicitly lock on the ArrayList you are returning. This is common with contended locks, switching the instance lock with a more localized grain.
In the third example, you lock on the Class. This is usually the preferred choice of static methods, where the instance cannot be acquired (try it, you can’t use “this” as a value). It’s pretty much equivalent to locking on a static final Object field, since the Class object theoretically shouldn’t change.
4
solved Synchronization – Difference between locks [duplicate]