当前位置: 代码迷 >> 综合 >> finalize() timed out after 10 seconds 问题模拟复现
  详细解决方案

finalize() timed out after 10 seconds 问题模拟复现

热度:41   发布时间:2024-02-06 20:32:39.0
public class Apple {@Overrideprotected void finalize() throws Throwable {super.finalize();Thread.sleep(130*1000);}
}

在 actvitity 中创建一个A pple 对象。

 

C rash Handler里拦截异常

import android.util.Log;import androidx.annotation.NonNull;import java.util.concurrent.TimeoutException;public class Te implements Thread.UncaughtExceptionHandler {@Overridepublic void uncaughtException(@NonNull Thread thread, @NonNull Throwable ex) {if (thread.getName().equals("FinalizerWatchdogDaemon") && (ex instanceof TimeoutException  || ex.getMessage().contains("timed out"))) {return; //Ignore}}
}

会报两个异常,分别是RuntimeException 和 TimeoutException

uncaughtException thread.getName FinalizerWatchdogDaemon##  ex.getMessage(.Apple.finalize() timed out after 10 seconds##  ex.getClass().getName()java.util.concurrent.TimeoutException

uncaughtException thread.getName FinalizerWatchdogDaemon##  ex.getMessage(java.util.concurrent.TimeoutException: .Apple.finalize() timed out after 10 seconds##  ex.getClass().getName()java.lang.RuntimeException

  相关解决方案