-
Notifications
You must be signed in to change notification settings - Fork 7.6k
2.x: Add scheduler creation factories #5002
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2ae2414
262f669
681b977
8b4d461
8009333
66111c5
a1029b4
e5c4a9e
90ae664
6a08b92
ea1ec6c
00af140
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,17 +12,19 @@ | |
*/ | ||
package io.reactivex.plugins; | ||
|
||
import java.lang.Thread.UncaughtExceptionHandler; | ||
import java.util.concurrent.Callable; | ||
|
||
import io.reactivex.internal.functions.ObjectHelper; | ||
import org.reactivestreams.Subscriber; | ||
|
||
import io.reactivex.*; | ||
import io.reactivex.annotations.Experimental; | ||
import io.reactivex.flowables.ConnectableFlowable; | ||
import io.reactivex.functions.*; | ||
import io.reactivex.internal.functions.ObjectHelper; | ||
import io.reactivex.internal.schedulers.*; | ||
import io.reactivex.internal.util.ExceptionHelper; | ||
import io.reactivex.observables.ConnectableObservable; | ||
import io.reactivex.schedulers.Schedulers; | ||
import org.reactivestreams.Subscriber; | ||
|
||
import java.lang.Thread.UncaughtExceptionHandler; | ||
import java.util.concurrent.*; | ||
|
||
/** | ||
* Utility class to inject handlers to certain standard RxJava operations. | ||
|
@@ -926,6 +928,58 @@ public static Completable onAssembly(Completable source) { | |
return source; | ||
} | ||
|
||
/** | ||
* Create an instance of the default {@link Scheduler} used for {@link Schedulers#computation()} | ||
* except using {@code threadFactory} for thread creation. | ||
* @param threadFactory thread factory to use for creating worker threads. Note that this takes precedence over any | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add notes to all of these methods something like this:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The "Note that this takes precedence..." may be misleading. The number of threads is still based on the system configuration. I'd remove this sentence entirely |
||
* system properties for configuring new thread creation. Cannot be null. | ||
* @return the created Scheduler instance | ||
* @since 2.0.5 - experimental | ||
*/ | ||
@Experimental | ||
public static Scheduler createComputationScheduler(ThreadFactory threadFactory) { | ||
return new ComputationScheduler(ObjectHelper.requireNonNull(threadFactory, "threadFactory is null")); | ||
} | ||
|
||
/** | ||
* Create an instance of the default {@link Scheduler} used for {@link Schedulers#io()} | ||
* except using {@code threadFactory} for thread creation. | ||
* @param threadFactory thread factory to use for creating worker threads. Note that this takes precedence over any | ||
* system properties for configuring new thread creation. Cannot be null. | ||
* @return the created Scheduler instance | ||
* @since 2.0.5 - experimental | ||
*/ | ||
@Experimental | ||
public static Scheduler createIoScheduler(ThreadFactory threadFactory) { | ||
return new IoScheduler(ObjectHelper.requireNonNull(threadFactory, "threadFactory is null")); | ||
} | ||
|
||
/** | ||
* Create an instance of the default {@link Scheduler} used for {@link Schedulers#newThread()} | ||
* except using {@code threadFactory} for thread creation. | ||
* @param threadFactory thread factory to use for creating worker threads. Note that this takes precedence over any | ||
* system properties for configuring new thread creation. Cannot be null. | ||
* @return the created Scheduler instance | ||
* @since 2.0.5 - experimental | ||
*/ | ||
@Experimental | ||
public static Scheduler createNewThreadScheduler(ThreadFactory threadFactory) { | ||
return new NewThreadScheduler(ObjectHelper.requireNonNull(threadFactory, "threadFactory is null")); | ||
} | ||
|
||
/** | ||
* Create an instance of the default {@link Scheduler} used for {@link Schedulers#single()} | ||
* except using {@code threadFactory} for thread creation. | ||
* @param threadFactory thread factory to use for creating worker threads. Note that this takes precedence over any | ||
* system properties for configuring new thread creation. Cannot be null. | ||
* @return the created Scheduler instance | ||
* @since 2.0.5 - experimental | ||
*/ | ||
@Experimental | ||
public static Scheduler createSingleScheduler(ThreadFactory threadFactory) { | ||
return new SingleScheduler(ObjectHelper.requireNonNull(threadFactory, "threadFactory is null")); | ||
} | ||
|
||
/** | ||
* Wraps the call to the function in try-catch and propagates thrown | ||
* checked exceptions as RuntimeException. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason why this was moved to the end?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It requires WORKER_THREAD_FACTORY to be initialized now since it's a parameter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right.