当我调用InputStream' close()时,它将完成超过10秒。我希望在1s完成

时间:2014-11-26 01:22:15

标签: java android connection inputstream

我看了Google provides 2 different examples of HttpURLConnection usage - Should we call HttpURLConnection's disconnect, or InputStream's close? 我知道在Android上使用close()是正确的。但是,当我关闭与InputStream' clos()的连接时,它需要花费10秒才能完成。我希望在1s完成关闭连接。我该怎么办?

    private HttpURLConnection getConnection(String uri) throws IOException {
    try {
        URL url = new URL(ROOT_URL + uri);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");

        connection.connect();

        DataInputStream dIS = new BufferedInputStream(connection.getInputStream(), 100000);

        dIS.close(); //it will finish over 10s

    } catch (IOException e) {
    }
}

0 个答案:

没有答案