开发者

Singleton Connection changes config. Best way to do

开发者 https://www.devze.com 2023-04-03 00:36 出处:网络
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?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消