Ok so as I understand it, its best to create a final static
Object that I use for synchronization.
However, I also read that if the object reference doesn't change, then it won't have concurrency issues.
Do the following code violate synchronicity?
class Foo {
private static ArrayList<Client> clients = null;
public Foo() {
clients = new ArrayList<>();
//add stuff to list here..
}
public void addClient(Client C) {
synchronized(clients) {
clients.add(C);
}
}
}
Do I have to make clients final or create a final object if the clients ArrayList
is never exposed directly (only other than through Getters)? In other words, I never provide a set method for the clients array so the reference never changes.