mirror of
https://github.com/moparisthebest/k-9
synced 2025-02-07 02:30:10 -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.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.RejectedExecutionException;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
@ -23,6 +24,7 @@ public abstract class CoreService extends Service
|
|||||||
private static AtomicInteger wakeLockSeq = new AtomicInteger(0);
|
private static AtomicInteger wakeLockSeq = new AtomicInteger(0);
|
||||||
private ExecutorService threadPool = null;
|
private ExecutorService threadPool = null;
|
||||||
private final String className = getClass().getName();
|
private final String className = getClass().getName();
|
||||||
|
private volatile boolean mShutdown = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate()
|
public void onCreate()
|
||||||
@ -146,8 +148,19 @@ public abstract class CoreService extends Service
|
|||||||
{
|
{
|
||||||
if (K9.DEBUG)
|
if (K9.DEBUG)
|
||||||
Log.d(K9.LOG_TAG, "CoreService (" + className + ") queueing Runnable " + runner.hashCode() + " with startId " + startId);
|
Log.d(K9.LOG_TAG, "CoreService (" + className + ") queueing Runnable " + runner.hashCode() + " with startId " + startId);
|
||||||
|
try
|
||||||
|
{
|
||||||
threadPool.execute(myRunner);
|
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);
|
public abstract void startService(Intent intent, int startId);
|
||||||
@ -159,11 +172,18 @@ public abstract class CoreService extends Service
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLowMemory()
|
||||||
|
{
|
||||||
|
Log.w(K9.LOG_TAG, "CoreService: " + className + ".onLowMemory() - Running low on memory");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy()
|
public void onDestroy()
|
||||||
{
|
{
|
||||||
if (K9.DEBUG)
|
if (K9.DEBUG)
|
||||||
Log.i(K9.LOG_TAG, "CoreService: " + className + ".onDestroy()");
|
Log.i(K9.LOG_TAG, "CoreService: " + className + ".onDestroy()");
|
||||||
|
mShutdown = true;
|
||||||
threadPool.shutdown();
|
threadPool.shutdown();
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
// MessagingController.getInstance(getApplication()).removeListener(mListener);
|
// MessagingController.getInstance(getApplication()).removeListener(mListener);
|
||||||
|
Loading…
Reference in New Issue
Block a user