由于缓冲区溢出导致数据流断开

时间:2012-05-25 05:41:29

标签: java inputstream

我在java中使用HttpURLConnection从数据提供程序获取Stream(JSON)。 BufferedReader用于读取和处理在multiThread中实现。如果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();
                }
            }

我做错了吗?为什么会出现此错误? 任何人都知道这个问题???

感谢。 -vibin

0 个答案:

没有答案