@@ -527,6 +527,12 @@ public final List<Runnable> shutdownNow() {
527
527
return delegate .shutdownNow ();
528
528
}
529
529
530
+ /*
531
+ * TODO: https://github.com/google/guava/issues/2143 - In addition to overriding `execute`, also
532
+ * override the `Future`-returning methods of `ExecutorService` to propagate cancellation from
533
+ * our `TrustedListenableFutureTask` to a `Future` returned by the delegate executor?
534
+ */
535
+
530
536
@ Override
531
537
public final void execute (Runnable command ) {
532
538
delegate .execute (command );
@@ -600,7 +606,12 @@ public boolean cancel(boolean mayInterruptIfRunning) {
600
606
// Unless it is cancelled, the delegate may continue being scheduled
601
607
scheduledDelegate .cancel (mayInterruptIfRunning );
602
608
603
- // TODO(user): Cancel "this" if "scheduledDelegate" is cancelled.
609
+ /*
610
+ * We'd love to also arrange for the inverse -- that is, to also automatically cancel this
611
+ * future if scheduledDelegate is cancelled (as happens after the delegate executor is
612
+ * shut down: https://github.com/google/guava/issues/3553). But it seems unlikely that
613
+ * that's possible to detect in general.
614
+ */
604
615
}
605
616
return cancelled ;
606
617
}
@@ -631,7 +642,24 @@ public void run() {
631
642
delegate .run ();
632
643
} catch (Throwable t ) {
633
644
// Any Exception is either a RuntimeException or sneaky checked exception.
645
+
646
+ /*
647
+ * We fail this `ListenableFuture`, whose result is exposed to the user through the
648
+ * `ListenableScheduledTask` we return from the `schedule*` methods.
649
+ */
634
650
setException (t );
651
+
652
+ /*
653
+ * We fail the current run of the recurring task so that it is not rescheduled. This also
654
+ * fails the `ScheduledFuture`, which might be visible only to users who operate directly
655
+ * on the delegate executor's queue.
656
+ *
657
+ * (Users who try to operate directly on the `ScheduledFuture` may have additional
658
+ * problems. For example, if they cancel that `Future`, it won't cancel the user-visible
659
+ * `ListenableScheduledTask`. This is essentially the same problem as the
660
+ * `ListenableScheduledTask` has with executor shutdown:
661
+ * https://github.com/google/guava/issues/3553)
662
+ */
635
663
throw t ;
636
664
}
637
665
}
0 commit comments