mirror of
https://github.com/moparisthebest/k-9
synced 2025-01-30 23:00:09 -05:00
Update issue 2270
Status: Fixed Gracefully ignore RejectedExecutionException on service shutdown (there's little we can do about being shut down)
This commit is contained in:
parent
aa46da06bb
commit
d28a85de5b
@ -3,6 +3,7 @@ package com.fsck.k9.service;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import android.app.Service;
|
||||
@ -23,6 +24,7 @@ public abstract class CoreService extends Service
|
||||
private static AtomicInteger wakeLockSeq = new AtomicInteger(0);
|
||||
private ExecutorService threadPool = null;
|
||||
private final String className = getClass().getName();
|
||||
private volatile boolean mShutdown = false;
|
||||
|
||||
@Override
|
||||
public void onCreate()
|
||||
@ -146,8 +148,19 @@ public abstract class CoreService extends Service
|
||||
{
|
||||
if (K9.DEBUG)
|
||||
Log.d(K9.LOG_TAG, "CoreService (" + className + ") queueing Runnable " + runner.hashCode() + " with startId " + startId);
|
||||
try
|
||||
{
|
||||
threadPool.execute(myRunner);
|
||||
}
|
||||
catch (RejectedExecutionException e)
|
||||
{
|
||||
if (!mShutdown)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
Log.i(K9.LOG_TAG, "CoreService: " + className + " is shutting down, ignoring rejected execution exception: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void startService(Intent intent, int startId);
|
||||
@ -159,11 +172,18 @@ public abstract class CoreService extends Service
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory()
|
||||
{
|
||||
Log.w(K9.LOG_TAG, "CoreService: " + className + ".onLowMemory() - Running low on memory");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy()
|
||||
{
|
||||
if (K9.DEBUG)
|
||||
Log.i(K9.LOG_TAG, "CoreService: " + className + ".onDestroy()");
|
||||
mShutdown = true;
|
||||
threadPool.shutdown();
|
||||
super.onDestroy();
|
||||
// MessagingController.getInstance(getApplication()).removeListener(mListener);
|
||||
|
Loading…
Reference in New Issue
Block a user