I have a Singleton Class to connect to http server. But the user can change the connection Host and Port. What is the best (most correct) way to update my singleton class?
M开发者_开发百科y code:
public class ServletConnectionManager{
private static ServletConnectionManager INSTANCE = new ServletConnectionManager(Cloud.getServlet_Port(), Cloud.getServlet_Host());
public ServletConnectionManager(String hostPort, String hostName) {
super();
this.setHostName(hostName);
this.setHostPort(hostPort);
this.setServerURL("http://" + hostName + ":" + hostPort);
}
}
Thank you very much. Sorry for my poor english
Just add yet another synchronized method to reset the connection based on new server location/user credentials changes. Even if doned transparently, you would have to make something similar when trying to reconnect after losing connection temporarily.
精彩评论