當前位置: 首頁>>代碼示例>>Java>>正文


Java Schedulers.from方法代碼示例

本文整理匯總了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();
}
 
開發者ID:PacktPublishing,項目名稱:Reactive-Android-Programming,代碼行數:17,代碼來源:Sandbox.java

示例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();
}
 
開發者ID:PacktPublishing,項目名稱:Reactive-Android-Programming,代碼行數:17,代碼來源:Sandbox.java

示例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();
}
 
開發者ID:aschattney,項目名稱:dagger-test-example,代碼行數:19,代碼來源:TestTomorrowWeatherViewModel.java

示例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();
}
 
開發者ID:aschattney,項目名稱:dagger-test-example,代碼行數:18,代碼來源:TestTodayWeatherViewModel.java

示例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);
}
 
開發者ID:PacktPublishing,項目名稱:Learning-RxJava,代碼行數:12,代碼來源:Ch6_7.java

示例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();
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:8,代碼來源:SendService.java

示例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;
}
 
開發者ID:XDean,項目名稱:Java-EX,代碼行數:9,代碼來源:RxSchedulers.java

示例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);
}
 
開發者ID:salesforce,項目名稱:pyplyn,代碼行數:13,代碼來源:TaskManager.java

示例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);
}
 
開發者ID:salesforce,項目名稱:pyplyn,代碼行數:13,代碼來源:TaskManager.java

示例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);
}
 
開發者ID:salesforce,項目名稱:pyplyn,代碼行數:13,代碼來源:TaskManager.java

示例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()));
}
 
開發者ID:aschattney,項目名稱:dagger-test-example,代碼行數:8,代碼來源:TestSearchService.java

示例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));
}
 
開發者ID:PacktPublishing,項目名稱:Reactive-Android-Programming,代碼行數:10,代碼來源:Sandbox.java

示例13: ExecutorBackedScheduler

import io.reactivex.schedulers.Schedulers; //導入方法依賴的package包/類
protected ExecutorBackedScheduler(ExecController execController) {
  this.execController = execController;
  this.delegateScheduler = Schedulers.from(getExecutor());
}
 
開發者ID:drmaas,項目名稱:ratpack-rx2,代碼行數:5,代碼來源:ExecutorBackedScheduler.java

示例14: localPoolConfiguration

import io.reactivex.schedulers.Schedulers; //導入方法依賴的package包/類
@Bean
@Conditional(NoTestSchedulerPresent.class)
public PoolConfiguration localPoolConfiguration() {
    return new PoolConfiguration(Schedulers.from(Executors.newFixedThreadPool(threadPoolSize)), observeOnCapacity);
}
 
開發者ID:streamingpool,項目名稱:streamingpool-core,代碼行數:6,代碼來源:DefaultPoolConfiguration.java

示例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())));
}
 
開發者ID:streamingpool,項目名稱:streamingpool-core,代碼行數:4,代碼來源:DiscoveryTest.java


注:本文中的io.reactivex.schedulers.Schedulers.from方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。