Skip to content

Commit af297c4

Browse files
authored
3.x: Schedulers.from vs. RejectedExecutionException (#7150)
1 parent b77aa1e commit af297c4

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/main/java/io/reactivex/rxjava3/schedulers/Schedulers.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,16 @@ public static Scheduler single() {
340340
* }
341341
* </code></pre>
342342
* <p>
343+
* Note that the provided {@code Executor} should avoid throwing a {@link RejectedExecutionException}
344+
* (for example, by shutting it down prematurely or using a bounded-queue {@code ExecutorService})
345+
* because such circumstances prevent RxJava from progressing flow-related activities correctly.
346+
* If the {@link Executor#execute(Runnable)} or {@link ExecutorService#submit(Callable)} throws,
347+
* the {@code RejectedExecutionException} is routed to the global error handler via
348+
* {@link RxJavaPlugins#onError(Throwable)}. To avoid shutdown-reladed problems, it is recommended
349+
* all flows using the returned {@code Scheduler} to be canceled/disposed before the underlying
350+
* {@code Executor} is shut down. To avoid problems due to the {@code Executor} having a bounded-queue,
351+
* it is recommended to rephrase the flow to utilize backpressure as the means to limit outstanding work.
352+
* <p>
343353
* This type of scheduler is less sensitive to leaking {@link io.reactivex.rxjava3.core.Scheduler.Worker Scheduler.Worker} instances, although
344354
* not disposing a worker that has timed/delayed tasks not cancelled by other means may leak resources and/or
345355
* execute those tasks "unexpectedly".
@@ -404,6 +414,16 @@ public static Scheduler from(@NonNull Executor executor) {
404414
* }
405415
* </code></pre>
406416
* <p>
417+
* Note that the provided {@code Executor} should avoid throwing a {@link RejectedExecutionException}
418+
* (for example, by shutting it down prematurely or using a bounded-queue {@code ExecutorService})
419+
* because such circumstances prevent RxJava from progressing flow-related activities correctly.
420+
* If the {@link Executor#execute(Runnable)} or {@link ExecutorService#submit(Callable)} throws,
421+
* the {@code RejectedExecutionException} is routed to the global error handler via
422+
* {@link RxJavaPlugins#onError(Throwable)}. To avoid shutdown-reladed problems, it is recommended
423+
* all flows using the returned {@code Scheduler} to be canceled/disposed before the underlying
424+
* {@code Executor} is shut down. To avoid problems due to the {@code Executor} having a bounded-queue,
425+
* it is recommended to rephrase the flow to utilize backpressure as the means to limit outstanding work.
426+
* <p>
407427
* This type of scheduler is less sensitive to leaking {@link io.reactivex.rxjava3.core.Scheduler.Worker Scheduler.Worker} instances, although
408428
* not disposing a worker that has timed/delayed tasks not cancelled by other means may leak resources and/or
409429
* execute those tasks "unexpectedly".
@@ -474,6 +494,16 @@ public static Scheduler from(@NonNull Executor executor, boolean interruptibleWo
474494
* }
475495
* </code></pre>
476496
* <p>
497+
* Note that the provided {@code Executor} should avoid throwing a {@link RejectedExecutionException}
498+
* (for example, by shutting it down prematurely or using a bounded-queue {@code ExecutorService})
499+
* because such circumstances prevent RxJava from progressing flow-related activities correctly.
500+
* If the {@link Executor#execute(Runnable)} or {@link ExecutorService#submit(Callable)} throws,
501+
* the {@code RejectedExecutionException} is routed to the global error handler via
502+
* {@link RxJavaPlugins#onError(Throwable)}. To avoid shutdown-reladed problems, it is recommended
503+
* all flows using the returned {@code Scheduler} to be canceled/disposed before the underlying
504+
* {@code Executor} is shut down. To avoid problems due to the {@code Executor} having a bounded-queue,
505+
* it is recommended to rephrase the flow to utilize backpressure as the means to limit outstanding work.
506+
* <p>
477507
* This type of scheduler is less sensitive to leaking {@link io.reactivex.rxjava3.core.Scheduler.Worker Scheduler.Worker} instances, although
478508
* not disposing a worker that has timed/delayed tasks not cancelled by other means may leak resources and/or
479509
* execute those tasks "unexpectedly".

0 commit comments

Comments
 (0)