单例连接更改配置。最好的办法
我有一个 Singleton 类来连接到 http 服务器。但用户可以更改连接的主机和端口。更新我的单例类的最佳(最正确)方法是什么?
我的代码:
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);
}
}
非常感谢。 抱歉我的英语不好
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?
My 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需添加另一个同步方法即可根据新的服务器位置/用户凭据更改重置连接。即使透明地完成,在暂时失去连接后尝试重新连接时,您也必须执行类似的操作。
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.