import libcore.util.EmptyArray;
+import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
}
public synchronized Future<?> scheduleWrite() {
+ if (mExecutorService.isShutdown()) {
+ return CompletableFuture.failedFuture(new IllegalStateException("worker shutdown"));
+ }
+
scheduleSyncLocked("write", UPDATE_ALL);
// Since we use a single threaded executor, we can assume the next scheduled task's
// Future finishes after the sync.
* within the task, never wait on the resulting Future. This will result in a deadlock.
*/
public synchronized void scheduleRunnable(Runnable runnable) {
- mExecutorService.submit(runnable);
+ if (!mExecutorService.isShutdown()) {
+ mExecutorService.submit(runnable);
+ }
}
public void shutdown() {
}
private Future<?> scheduleSyncLocked(String reason, int flags) {
+ if (mExecutorService.isShutdown()) {
+ return CompletableFuture.failedFuture(new IllegalStateException("worker shutdown"));
+ }
+
if (mCurrentFuture == null) {
mUpdateFlags = flags;
mCurrentReason = reason;