我在 java 中使用 HttpURLConnection 从数据提供者获取 Stream(JSON)。BufferedReader 用于读取和处理是在多线程中实现的。当 JSON 流达到每秒 200 个时很好,如果提供者断开更多流并出现此错误
Force closing connection to xxx.xxx.xxx.xx because it reached the maximum allowed backup (buffer size is 2343 messages)
我用来检索数据的代码是。
pool = new ThreadPoolExecutor(150, 200, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue());
connection = getConnection(dataCollectorURL, username, password);
inputStream = connection.getInputStream();
if(inputStream!=null)
{
int responseCode = connection.getResponseCode();
if (responseCode >= 200 && responseCode <= 299) {
long time = Runtime.getRuntime().freeMemory();
BufferedReader reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(inputStream, 100*1024),"utf-8"),100*1024);
BufferedReader errorReader = null;
String line = reader.readLine();
while(line != null){
jParser = new ObjectMapper().getJsonFactory().createJsonParser(line);
try
{
pool.execute(new ParseJSONTwitter(jParser.readValueAsTree()));
if(loopCount==100)
{
printThreadStatus();
loopCount = 0;
}
loopCount++;
}
catch(IOException e)
{
e.printStackTrace();
}
if(reader.ready())
{
line = reader.readLine();
}
else
{
line = null;
}
}
if(!(responseCode>=200 && responseCode<=299) || line==null)
{
if(inputStream!=null)
{
inputStream.close();//To free n/w resources
}
reconnect();
}
} else {
handleNonSuccessResponse(connection);
if(inputStream!=null)
{
inputStream.close();//To free n/w resources
}
reconnect();
}
}
难道我做错了什么?为什么会出现这个错误?有谁知道这个问题???
谢谢。-维宾