finalize() timed out after 10 seconds problem simulation recurrence

public class Apple {
    @Override
    protected void finalize() throws Throwable {
        super.finalize();
        Thread.sleep(130*1000);
    }
}

Create an A pple object in actvitity.

 

Intercept exceptions in C rash Handler

import android.util.Log;

import androidx.annotation.NonNull;

import java.util.concurrent.TimeoutException;

public class Te implements Thread.UncaughtExceptionHandler {

    @Override
    public void uncaughtException(@NonNull Thread thread, @NonNull Throwable ex) {
        if (thread.getName().equals("FinalizerWatchdogDaemon") && (ex instanceof TimeoutException  || ex.getMessage().contains("timed out"))) {
            return; //Ignore
        }
    }
}

Two exceptions will be reported, namely RuntimeException and 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

Guess you like

Origin blog.csdn.net/wuzhong8809/article/details/107815931