java.net.sockettimeoutexception: read timed out的问题

查看:130
本文介绍了java.net.sockettimeoutexception: read timed out的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

client有如下伪代码:

try{
    Socket ss = new Socket();
    ss.connect(new InetSocketAddress(127.0.0.1, TCPServer.LISTEN_PORT), 4000);
    ss.setSoTimeout(5000);
    
    //dosomthing
    InputStream is = ss.getInputStrean();
    log.info("read start time:" + System.currentTimeMillis())
    int r = is.read(....);
    log.info("read start time:" + System.currentTimeMillis())
} catch(Exception e){
    log.info("throw exception time:" + System.currentTimeMillis());
}

上面这样的逻辑,ss.setSoTimeout(5000);把读超时设置为5000ms,可经过测试read的时间也不过才619ms 就抛出了如题的异常?

解决方案

这是服务端是同步通知,时间过长,把服务端修改成异步的即可

这篇关于java.net.sockettimeoutexception: read timed out的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆