6161 * can detect the earlier hook and not apply a new one over again.
6262 * <p>
6363 * The default implementation of {@link #now(TimeUnit)} and {@link Worker#now(TimeUnit)} methods to return current {@link System#currentTimeMillis()}
64- * value in the desired time unit, unless {@code rx4 .scheduler.use-nanotime} (boolean) is set. When the property is set to
64+ * value in the desired time unit, unless {@code rxjava4 .scheduler.use-nanotime} (boolean) is set. When the property is set to
6565 * {@code true}, the method uses {@link System#nanoTime()} as its basis instead. Custom {@code Scheduler} implementations can override this
6666 * to provide specialized time accounting (such as virtual time to be advanced programmatically).
6767 * Note that operators requiring a {@code Scheduler} may rely on either of the {@code now()} calls provided by
7474 * based on the relative time between it and {@link Worker#now(TimeUnit)}. However, drifts or changes in the
7575 * system clock could affect this calculation either by scheduling subsequent runs too frequently or too far apart.
7676 * Therefore, the default implementation uses the {@link #clockDriftTolerance()} value (set via
77- * {@code rx4 .scheduler.drift-tolerance} and {@code rx4 .scheduler.drift-tolerance-unit}) to detect a
77+ * {@code rxjava4 .scheduler.drift-tolerance} and {@code rxjava4 .scheduler.drift-tolerance-unit}) to detect a
7878 * drift in {@link Worker#now(TimeUnit)} and re-adjust the absolute/relative time calculation accordingly.
7979 * <p>
8080 * The default implementations of {@link #start()} and {@link #shutdown()} do nothing and should be overridden if the
@@ -95,10 +95,10 @@ public abstract class Scheduler {
9595 * <p>
9696 * Associated system parameter:
9797 * <ul>
98- * <li>{@code rx4 .scheduler.use-nanotime}, boolean, default {@code false}
98+ * <li>{@code rxjava4 .scheduler.use-nanotime}, boolean, default {@code false}
9999 * </ul>
100100 */
101- static boolean IS_DRIFT_USE_NANOTIME = Boolean .getBoolean ("rx4 .scheduler.use-nanotime" );
101+ static boolean IS_DRIFT_USE_NANOTIME = Boolean .getBoolean ("rxjava4 .scheduler.use-nanotime" );
102102
103103 /**
104104 * Returns the current clock time depending on state of {@link Scheduler#IS_DRIFT_USE_NANOTIME} in given {@code unit}
@@ -122,15 +122,15 @@ static long computeNow(TimeUnit unit) {
122122 * <p>
123123 * Associated system parameters:
124124 * <ul>
125- * <li>{@code rx4 .scheduler.drift-tolerance}, long, default {@code 15}</li>
126- * <li>{@code rx4 .scheduler.drift-tolerance-unit}, string, default {@code minutes},
125+ * <li>{@code rxjava4 .scheduler.drift-tolerance}, long, default {@code 15}</li>
126+ * <li>{@code rxjava4 .scheduler.drift-tolerance-unit}, string, default {@code minutes},
127127 * supports {@code seconds} and {@code milliseconds}.
128128 * </ul>
129129 */
130130 static final long CLOCK_DRIFT_TOLERANCE_NANOSECONDS =
131131 computeClockDrift (
132- Long .getLong ("rx4 .scheduler.drift-tolerance" , 15 ),
133- System .getProperty ("rx4 .scheduler.drift-tolerance-unit" , "minutes" )
132+ Long .getLong ("rxjava4 .scheduler.drift-tolerance" , 15 ),
133+ System .getProperty ("rxjava4 .scheduler.drift-tolerance-unit" , "minutes" )
134134 );
135135
136136 /**
@@ -152,8 +152,8 @@ static long computeClockDrift(long time, String timeUnit) {
152152 * Returns the clock drift tolerance in nanoseconds.
153153 * <p>Related system properties:
154154 * <ul>
155- * <li>{@code rx4 .scheduler.drift-tolerance}, long, default {@code 15}</li>
156- * <li>{@code rx4 .scheduler.drift-tolerance-unit}, string, default {@code minutes},
155+ * <li>{@code rxjava4 .scheduler.drift-tolerance}, long, default {@code 15}</li>
156+ * <li>{@code rxjava4 .scheduler.drift-tolerance-unit}, string, default {@code minutes},
157157 * supports {@code seconds} and {@code milliseconds}.
158158 * </ul>
159159 * @return the tolerance in nanoseconds
@@ -320,6 +320,24 @@ public ExecutorService toExecutorService(boolean useWorker) {
320320 return new SchedulerToExecutorService (this , new AtomicReference <>(useWorker ? createWorker () : null ));
321321 }
322322
323+ /**
324+ * Creates a new {@code Scheduler} that uses one of the Workers from this Scheduler
325+ * and shares the access to it through its own Workers.
326+ * <p>
327+ * Disposing a worker doesn't dispose the underlying shared worker so other
328+ * workers of this class can continue their work; use {@link #shutdown()} to release
329+ * the underlying shared worker.
330+ * <p>
331+ * This scheduler doesn't support {@link #start()} (it's a no-op) and once {@link #shutdown()}
332+ * it can't be revived.
333+ * @return the shared Scheduler instance
334+ * @since 4.0.0
335+ */
336+ @ NonNull
337+ public Scheduler share () {
338+ return createWorker ().share ();
339+ }
340+
323341 /**
324342 * Represents an isolated, sequential worker of a parent Scheduler for executing {@code Runnable} tasks on
325343 * an underlying task-execution scheme (such as custom Threads, event loop, {@link java.util.concurrent.Executor Executor} or Actor system).
@@ -332,7 +350,7 @@ public ExecutorService toExecutorService(boolean useWorker) {
332350 * {@link #dispose()} can prevent their execution or potentially interrupt them if they are currently running.
333351 * <p>
334352 * The default implementation of the {@link #now(TimeUnit)} method returns current {@link System#currentTimeMillis()}
335- * value in the desired time unit, unless {@code rx4 .scheduler.use-nanotime} (boolean) is set. When the property is set to
353+ * value in the desired time unit, unless {@code rxjava4 .scheduler.use-nanotime} (boolean) is set. When the property is set to
336354 * {@code true}, the method uses {@link System#nanoTime()} as its basis instead. Custom {@code Worker} implementations can override this
337355 * to provide specialized time accounting (such as virtual time to be advanced programmatically).
338356 * Note that operators requiring a scheduler may rely on either of the {@code now()} calls provided by
@@ -345,7 +363,7 @@ public ExecutorService toExecutorService(boolean useWorker) {
345363 * based on the relative time between it and {@link #now(TimeUnit)}. However, drifts or changes in the
346364 * system clock would affect this calculation either by scheduling subsequent runs too frequently or too far apart.
347365 * Therefore, the default implementation uses the {@link #clockDriftTolerance()} value (set via
348- * {@code rx4 .scheduler.drift-tolerance} and {@code rx4 .scheduler.drift-tolerance-unit}) to detect a drift in {@link #now(TimeUnit)} and
366+ * {@code rxjava4 .scheduler.drift-tolerance} and {@code rxjava4 .scheduler.drift-tolerance-unit}) to detect a drift in {@link #now(TimeUnit)} and
349367 * re-adjust the absolute/relative time calculation accordingly.
350368 * <p>
351369 * If the {@code Worker} is disposed, the {@code schedule} methods
@@ -455,6 +473,24 @@ public long now(@NonNull TimeUnit unit) {
455473 return computeNow (unit );
456474 }
457475
476+ /**
477+ * Creates a new {@code Scheduler} that uses this Worker
478+ * and shares the access to it through its own Workers.
479+ * <p>
480+ * Disposing a worker doesn't dispose the underlying shared worker so other
481+ * workers of this class can continue their work; use {@link #shutdown()} to release
482+ * the underlying shared worker.
483+ * <p>
484+ * This scheduler doesn't support {@link #start()} (it's a no-op) and once {@link #shutdown()}
485+ * it can't be revived.
486+ * @return the shared Scheduler instance
487+ * @since 4.0.0
488+ */
489+ @ NonNull
490+ public Scheduler share () {
491+ return new SharedScheduler (this );
492+ }
493+
458494 /**
459495 * Holds state and logic to calculate when the next delayed invocation
460496 * of this task has to happen (accounting for clock drifts).
0 commit comments