多线程批量处理任务需要频繁用http请求接口,任务跑了十几天后忽然报错500 error。
开始以为是因为频率太快导致错误。因为处理时间完成没要求,所以决定对每个任务进行了延时500ms处理。
几天后忽然又报错Caused by: java.lang.NoClassDefFoundError: org/apache/http/impl/client/RequestWrapper
看到这个错以为是因为http请求时候资源没有及时释放,然后在代码里面加入以下代码
request.releaseConnection(); //释放request
if (null != httpClient) {
HttpClientUtils.closeQuietly(httpClient); //关闭连接
}
if (null != response)
try {
response.close(); //关闭response
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
几天后又报错(为什么是几天后才报错,可能是重启了服务的原因)
后发现http自己会释放这些资源
以上都是弯路
然后延时去了,问题返回到报错500和java.net.SocketException: Too many open files错误
<html>
<head><title>500 Internal Server Error</title></head>
<body bgcolor="white">
<center><h1>500 Internal Server Error</h1></center>
<hr><center>nginx/1.11.3</center>
</body>
</html>
细心一看中间层nginx已经报错了。
查看nginx的error日志发现问题
原来是open files参数设置过小1024不能满足。
设置成10240后问题解决。
(技术水平有限,敬请指教。感恩!)