I'm trying to make Clients
class singleton, but it is not working. Here is my class:
public class Clients {
private static Clients instance = null;
private ArrayList<Client> cList;
private Clients() {
cList = new ArrayList<Client>();
}
public static Clients getInstance() {
if (instance == null) {
System .out.println("created");
instance = new Clients();
}
return instance;
}
public static ArrayList<Client> getcList() {
return getInstance().cList;
}
public static void setcList(ArrayList<Client> cList) {
getInstance().cList = cList;
}
}
I am getting this instance in two different classes(both have their own main function). After getting its instance in one class, I get it in another class, but both tiare still executing.