What is the difference between the following approaches of placing a lock with concurrency?
public synchronized ArrayList<Player> getPlayers() {
return players;
}
public ArrayList<Player> getPlayers() {
synchronized(players) {
return players;
}
}
public ArrayList<Player> getPlayers() {
synchronized(GameHandler.class) {
return players;
}
}
How do we decide which one should be used in which scenarios?
Edit:
I have edited my thread title and post to prove this is not a duplicate. Thank you.