网络不通错误No buffer space available解决方案分享

时间:2018-10-11
本文章向大家介绍网络不通错误No buffer space available解决方案分享,需要的朋友可以参考一下

生产环境,突然爆发问题,网络正常,但是报网络不通错误,重启tomcat立刻好使

开始以为是tomcat的问题,调查了很久,后来加上堆栈日志才发现

简单来说,就是1-4分钟之内,使用了大量的http请求,达到了操作系统限制的最大值,所以许多请求处于wait状态,导致程序错误

原代码,httpClient 未关闭

finally {
            if (is != null) {
                is.close();
            }
            if (postMethod != null) {
                postMethod.releaseConnection();
            }
        }

新代码,httpClient正确关闭

finally {
            if (is != null) {
                try{
                is.close();
                }catch(Exception e){
                    
                }
            }
            if(postMethod!=null)
                postMethod.releaseConnection();
            if(httpClient!=null)
                httpClient.getHttpConnectionManager().closeIdleConnections(0);
        }

祝开发顺利!