Java Socket 创建需要更多时间
我已经给出了 Socket soc = new Socket(host,port); 现在,当主机启动并处于运行状态时,套接字将立即创建。
但是当机器关闭或重新启动时,该行大约需要 40 秒才能响应。我尝试使用 soc.setSoTimeout(timeout);
但这行是在创建 Socket 之后使用的。因此它没有多大帮助。
而且这似乎是JAVA本身的一个错误。 https://bugs.java.com/bugdatabase/view_bug;:YfiG? bug_id=5092063
我尝试了此链接中给出的一些解决方法,例如在 etc/hosts 文件中添加计算机端口和主机名。但这不起作用。由于套接字创建时 DNS 解析造成的延迟,系统的响应时间受到严重影响。
任何帮助将不胜感激。
谢谢, 锶
I have given Socket soc = new Socket(host,port);
Now when the host machine is up and in running state, the socket is getting created immediately.
But when the machine is turned off or rebooted then this line takes around 40 seconds to respond. I tried using soc.setSoTimeout(timeout);
But this line is used after creation of Socket. Hence it doesn't help much.
Also this seems to be a bug in JAVA itself.
https://bugs.java.com/bugdatabase/view_bug;:YfiG?bug_id=5092063
I have tried few workarounds given in this link like adding the machine port and host name in the etc/hosts file. But it doesn't work. Because of this delay due to DNS resolution while socket creation, the response time of my system gets severely affected.
Any help would be greatly appreciated.
thanks,
Sr
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 使用超时连接方法
Use the connect with timeout method