Debian Codegraph @

src/main/java/io/reactivex/rxjava3/internal/schedulers/NewThreadScheduler.java

raw
1 /*
2 * Copyright (c) 2016-present, RxJava Contributors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
5 * compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is
10 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
11 * the License for the specific language governing permissions and limitations under the License.
12 */
13
14 package io.reactivex.rxjava3.internal.schedulers;
15
16 import java.util.concurrent.ThreadFactory;
17
18 import io.reactivex.rxjava3.annotations.NonNull;
19 import io.reactivex.rxjava3.core.Scheduler;
20
21 /**
22 * Schedules work on a new thread.
23 */
24 public final class NewThreadScheduler extends Scheduler {
25
26 final ThreadFactory threadFactory;
27
28 private static final String THREAD_NAME_PREFIX = "RxNewThreadScheduler";
29 private static final RxThreadFactory THREAD_FACTORY;
30
31 /** The name of the system property for setting the thread priority for this Scheduler. */
32 private static final String KEY_NEWTHREAD_PRIORITY = "rx3.newthread-priority";
33
34 static {
35 int priority = Math.max(Thread.MIN_PRIORITY, Math.min(Thread.MAX_PRIORITY,
36 Integer.getInteger(KEY_NEWTHREAD_PRIORITY, Thread.NORM_PRIORITY)));
37
38 THREAD_FACTORY = new RxThreadFactory(THREAD_NAME_PREFIX, priority);
39 }
40
41 public NewThreadScheduler() {
42 this(THREAD_FACTORY);
43 }
44
45 public NewThreadScheduler(ThreadFactory threadFactory) {
46 this.threadFactory = threadFactory;
47 }
48
49 @NonNull
50 @Override
51 public Worker createWorker() {
52 return new NewThreadWorker(threadFactory);
53 }
54 }