AssetManager $ AssetInputStream.finalize()在10秒后超时

时间:2014-12-09 15:10:01

标签: android performance crash samsung-mobile

我们在Android 4.3 Samsung Galaxy s3上看到了以下崩溃的流,

java.util.concurrent.TimeoutException: android.content.res.AssetManager$AssetInputStream.finalize() timed out after 10 seconds
       at android.content.res.AssetManager$AssetInputStream.close(AssetManager.java:559)
       at android.content.res.AssetManager$AssetInputStream.finalize(AssetManager.java:592)
       at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:187)
       at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:170)
       at java.lang.Thread.run(Thread.java:841)

帮助任何人?

1 个答案:

答案 0 :(得分:0)

无论何时使用StreamReader / StreamWriter类进行读/写操作,请确保在第一个ioStream.close()块内调用try{}。像这样:

    AssetManager AssetManager = mContext.getAssets();
    try {
        InputStream is = AssetManager.open("sample.json");
        int size = is.available();
        byte[] buffer = new byte[size];
        is.read(buffer);
        is.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }

即使您在try{}块下还有另一个catch/finally {}块,它也会抛出异常。

相反,您可以在ioStream = null块中分配catch/finally {}

catch (Exception ex) {
  // If ioStream object is outside the try block
  ioStream = null;
}