Added sail-safe

This commit is contained in:
M66B 2023-01-13 18:24:21 +01:00
parent 8a166a5000
commit c2c4683d12
1 changed files with 9 additions and 4 deletions

View File

@ -359,11 +359,16 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
}
void cancel(Context context) {
ExecutorService executor = getExecutor(context);
if (executor instanceof ThreadPoolExecutor && future instanceof Runnable) {
boolean removed = ((ThreadPoolExecutor) executor).remove((Runnable) future);
Log.i("Remove task=" + name + " removed=" + removed);
try {
ExecutorService executor = getExecutor(context);
if (executor instanceof ThreadPoolExecutor && future instanceof Runnable) {
boolean removed = ((ThreadPoolExecutor) executor).remove((Runnable) future);
Log.i("Remove task=" + name + " removed=" + removed);
}
} catch (Throwable ex) {
Log.e(ex);
}
if (future != null && future.cancel(false)) {
Log.i("Cancelled task=" + name);
cleanup(context);