RxJava icon indicating copy to clipboard operation
RxJava copied to clipboard

Request for clarification for Scheduler.Worker JavaDoc

Open rzsombor opened this issue 10 years ago • 2 comments

On 1.x, currently the JavaDoc states the following on Scheduler.Worker:

 /**
 * Retrieves or creates a new {@link Scheduler.Worker} that represents serial execution of actions.
 * <p>
 * When work is completed it should be unsubscribed using {@link Scheduler.Worker#unsubscribe()}.
 * <p>
 * Work on a {@link Scheduler.Worker} is guaranteed to be sequential.
 * 
 * @return a Worker representing a serial queue of actions to be executed
 */

I think the confusing part is deciding exactly what is going to be sequential. For me, based on this description it appeared that submitted Worker Actions will be executed sequentially, without any parallel execution within a Worker instance. This is apparently not the case with most current Workers looking into their implementation (e.g. NewThreadScheduler).

I'm happy to submit a PR with a more specific description, just wanted to make sure that you guys also see this problematic.

rzsombor avatar Apr 30 '16 14:04 rzsombor

Here are two other javadocs for comparison:

https://github.com/reactor/reactive-streams-commons/blob/master/src/main/java/rsc/scheduler/Scheduler.java

https://github.com/reactor/reactive-streams-commons/blob/master/src/main/java/rsc/scheduler/TimedScheduler.java

RxJava workers guarantee FIFO order for non-timed task and some order between timed tasks, but tasks never run concurrently with each other on the same worker no matter what the underlying threading model is. For example, this is guaranteed in NewThreadWorker because it uses a single-threaded ScheduledExecutorService. For ExecutorScheduler, the FIFO nature is ensured by additional trampolining.

akarnokd avatar Apr 30 '16 14:04 akarnokd

Fair point, the pieces clicked together now - thanks for the clarification!

rzsombor avatar Apr 30 '16 15:04 rzsombor