本文整理汇总了Java中io.reactivex.schedulers.Schedulers.from方法的典型用法代码示例。如果您正苦于以下问题:Java Schedulers.from方法的具体用法?Java Schedulers.from怎么用?Java Schedulers.from使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.reactivex.schedulers.Schedulers
的用法示例。
在下文中一共展示了Schedulers.from方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: demo2
import io.reactivex.schedulers.Schedulers; //导入方法依赖的package包/类
private static void demo2() throws Exception {
final ExecutorService executor = Executors.newFixedThreadPool(1000);
final Scheduler pooledScheduler = Schedulers.from(executor);
Observable.range(1, 10000)
.flatMap(i -> Observable.just(i)
.subscribeOn(pooledScheduler)
.map(Sandbox::importantLongTask)
)
.doOnTerminate(WAIT_LATCH::countDown)
.map(Object::toString)
.subscribe(e -> log("subscribe", e));
WAIT_LATCH.await();
executor.shutdown();
}
示例2: demo2
import io.reactivex.schedulers.Schedulers; //导入方法依赖的package包/类
private static void demo2() throws Exception {
final ExecutorService executor = Executors.newFixedThreadPool(1000);
final Scheduler pooledScheduler = Schedulers.from(executor);
Observable.range(1, 10000)
.flatMap(i -> Observable.just(i)
.subscribeOn(pooledScheduler)
.map(Sandbox::importantLongTask)
)
.doOnTerminate(WAIT_LATCH::countDown)
.map(Objects::toString)
.subscribe(e -> log("subscribe", e));
WAIT_LATCH.await();
executor.shutdown();
}
示例3: setUp
import io.reactivex.schedulers.Schedulers; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
permissionSubject = PublishSubject.create();
locationSubject = PublishSubject.create();
pageChanged = PublishSubject.create();
doReturn(permissionSubject).when(pm).onPermissionGranted();
doReturn(locationSubject).when(locationService).onNewLocation();
doReturn(true).when(locationService).isGpsProviderEnabled();
doReturn(Observable.empty()).when(weatherService).getTomorrowWeather(anyDouble(), anyDouble());
final Scheduler androidScheduler = Schedulers.from(new CurrentThreadExecutor());
vm = new TomorrowWeatherViewModel(navigation, pageChanged, pm,
locationService, weatherService, weatherParser, androidScheduler);
vm.state = new WeatherViewModel.WeatherViewModelState();
}
示例4: setUp
import io.reactivex.schedulers.Schedulers; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
permissionSubject = PublishSubject.create();
locationSubject = PublishSubject.create();
pageChanged = PublishSubject.create();
doReturn(permissionSubject).when(pm).onPermissionGranted();
doReturn(locationSubject).when(locationService).onNewLocation();
doReturn(true).when(locationService).isGpsProviderEnabled();
doReturn(Observable.empty()).when(weatherService).getCurrentWeather(anyDouble(), anyDouble());
final Scheduler androidScheduler = Schedulers.from(new CurrentThreadExecutor());
vm = new TodayWeatherViewModel(navigation, pageChanged, pm, locationService, weatherService, weatherParser, androidScheduler);
vm.state = new WeatherViewModel.WeatherViewModelState();
}
示例5: main
import io.reactivex.schedulers.Schedulers; //导入方法依赖的package包/类
public static void main(String[] args) {
int numberOfThreads = 20;
ExecutorService executor =
Executors.newFixedThreadPool(numberOfThreads);
Scheduler scheduler = Schedulers.from(executor);
Observable.just("Alpha", "Beta", "Gamma", "Delta",
"Epsilon")
.subscribeOn(scheduler)
.doFinally(executor::shutdown)
.subscribe(System.out::println);
}
示例6: onCreate
import io.reactivex.schedulers.Schedulers; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
this.messagesInteractor = InteractorFactory.createMessagesInteractor();
this.mSenderScheduler = Schedulers.from(Executors.newFixedThreadPool(1));
this.registeredAccounts = Settings.get().accounts().getRegistered();
}
示例7: autoClose
import io.reactivex.schedulers.Schedulers; //导入方法依赖的package包/类
public static Scheduler autoClose(ExecutorService pool) {
Scheduler scheduler = Schedulers.from(pool);
FinalizeSupport.finalize(scheduler, () -> {
debug().log("Shutdown the scheduler from: " + pool);
pool.shutdown();
});
return scheduler;
}
示例8: initExtractScheduler
import io.reactivex.schedulers.Schedulers; //导入方法依赖的package包/类
/**
* Initializes a scheduler that will be used for offloading IO work performed by {@link Extract}s
* <p/>
* <p/> Threads executed on this scheduler have {@link Thread#NORM_PRIORITY}
* @param ioPoolSize Size of thread pool for this scheduler
*/
private Scheduler initExtractScheduler(Integer ioPoolSize) {
ThreadFactory factory = newThreadFactory("TaskManager-Extract-%s", Thread.NORM_PRIORITY);
ExecutorService executor = Executors.newFixedThreadPool(ioPoolSize, factory);
shutdownHook.registerExecutor(executor);
return Schedulers.from(executor);
}
示例9: initTransformScheduler
import io.reactivex.schedulers.Schedulers; //导入方法依赖的package包/类
/**
* Initializes a scheduler that will be used for offloading IO work performed by {@link PollingTransform}s
* <p/>
* <p/> Threads executed on this scheduler have {@link Thread#NORM_PRIORITY+1}
* @param ioPoolSize Size of thread pool for this scheduler
*/
private Scheduler initTransformScheduler(Integer ioPoolSize) {
ThreadFactory factory = newThreadFactory("TaskManager-Transform-%s", Thread.NORM_PRIORITY + 1);
ExecutorService executor = Executors.newFixedThreadPool(ioPoolSize, factory);
shutdownHook.registerExecutor(executor);
return Schedulers.from(executor);
}
示例10: initLoadScheduler
import io.reactivex.schedulers.Schedulers; //导入方法依赖的package包/类
/**
* Initializes a scheduler that will be used for offloading IO work performed by {@link Load}s
* <p/>
* <p/> Threads executed on this scheduler have {@link Thread#NORM_PRIORITY}+2
* @param ioPoolSize Size of thread pool for this scheduler
*/
private Scheduler initLoadScheduler(Integer ioPoolSize) {
ThreadFactory factory = newThreadFactory("TaskManager-Load-%s", Thread.NORM_PRIORITY + 2);
ExecutorService executor = Executors.newFixedThreadPool(ioPoolSize, factory);
shutdownHook.registerExecutor(executor);
return Schedulers.from(executor);
}
示例11: setUp
import io.reactivex.schedulers.Schedulers; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
item = fakeResponse(Responses.JSON.SEARCH);
doReturn(Observable.just(item))
.when(weatherApi).searchWeather(anyString());
searchService = new SearchService(weatherApi, Schedulers.from(new CurrentThreadExecutor()));
}
示例12: demo3
import io.reactivex.schedulers.Schedulers; //导入方法依赖的package包/类
private static void demo3() {
final ExecutorService executor = Executors.newFixedThreadPool(10);
final Scheduler pooledScheduler = Schedulers.from(executor);
Observable.range(1, 100)
.subscribeOn(pooledScheduler)
.map(Objects::toString)
.subscribe(e -> log("subscribe", e));
}
示例13: ExecutorBackedScheduler
import io.reactivex.schedulers.Schedulers; //导入方法依赖的package包/类
protected ExecutorBackedScheduler(ExecController execController) {
this.execController = execController;
this.delegateScheduler = Schedulers.from(getExecutor());
}
示例14: localPoolConfiguration
import io.reactivex.schedulers.Schedulers; //导入方法依赖的package包/类
@Bean
@Conditional(NoTestSchedulerPresent.class)
public PoolConfiguration localPoolConfiguration() {
return new PoolConfiguration(Schedulers.from(Executors.newFixedThreadPool(threadPoolSize)), observeOnCapacity);
}
示例15: prepareDiscoveryService
import io.reactivex.schedulers.Schedulers; //导入方法依赖的package包/类
private DiscoveryService prepareDiscoveryService(final List<StreamFactory> factories) {
return new LocalPool(factories, new PoolConfiguration(Schedulers.from(Executors.newSingleThreadExecutor())));
}