Implemented TODO in CoreService

The todo:
    // TODO: remove this. we never set threadPool to null

    The fix:
    Removed most code that would be executed if threadPool were null
    Reordered a little logic to make code easier to read
This commit is contained in:
Joshua Nelson 2017-10-30 15:10:39 -04:00
parent d696723023
commit 4178306273

View file

@ -324,30 +324,19 @@ public abstract class CoreService extends Service {
} }
}; };
// TODO: remove this. we never set mThreadPool to null Timber.d("CoreService (%s) queueing Runnable %d with startId %d", className, runner.hashCode(), startId);
if (mThreadPool == null) {
Timber.e("CoreService.execute (%s) called with no thread pool available; " +
"running Runnable %d in calling thread", className, runner.hashCode());
synchronized (this) {
myRunner.run();
serviceShutdownScheduled = startId != null;
}
} else {
Timber.d("CoreService (%s) queueing Runnable %d with startId %d", className, runner.hashCode(), startId);
try {
mThreadPool.execute(myRunner);
serviceShutdownScheduled = startId != null;
} catch (RejectedExecutionException e) {
// Ignore RejectedExecutionException after we shut down the thread pool in
// onDestroy(). Still, this should not happen!
if (!mShutdown) {
throw e;
}
try {
mThreadPool.execute(myRunner);
serviceShutdownScheduled = startId != null;
} catch (RejectedExecutionException e) {
// Ignore RejectedExecutionException after we shut down the thread pool in
// onDestroy(). Still, this should not happen!
if (mShutdown) {
Timber.i("CoreService: %s is shutting down, ignoring rejected execution exception: %s", Timber.i("CoreService: %s is shutting down, ignoring rejected execution exception: %s",
className, e.getMessage()); className, e.getMessage());
} else {
throw e;
} }
} }