rxJava Schedulers Use Cases
来源:互联网 发布:淘宝虎扑识货推荐店铺 编辑:程序博客网 时间:2024/05/17 01:12
官方:
immediate(): Creates and returns a Scheduler that executes work immediately on the current thread.
trampoline(): Creates and returns a Scheduler that queues work on the current thread to be executed after the current work completes.newThread(): Creates and returns a Scheduler that creates a new Thread for each unit of work.
computation(): Creates and returns a Scheduler intended for computational work. This can be used for event-loops, processing callbacks and other computational work. Do not perform IO-bound work on this scheduler. Use Schedulers.io() instead.
io(): Creates and returns a Scheduler intended for IO-bound work. The implementation is backed by an Executor thread-pool that will grow as needed. This can be used for asynchronously performing blocking IO. Do not perform computational work on this scheduler. Use Schedulers.computation() instead.
解释:
io() is backed by an unbounded thread-pool and is the sort of thing you'd use for non-computationally intensive tasks, that is stuff that doesn't put much load on the CPU. So yep interaction with the file system, interaction with databases or services on a different host are good examples.
computation() is backed by a bounded thread-pool with size equal to the number of available processors. If you tried to schedule cpu intensive work in parallel across more than the available processors (say using newThread()) then you are up for thread creation overhead and context switching overhead as threads vie for a processor and it's potentially a big performance hit.
It's best to leave computation() for CPU intensive work only otherwise you won't get good CPU utilization.
It's bad to call io() for computational work for the reason discussed in 2. io() is unbounded and if you schedule a thousand computational tasks on io() in parallel then each of those thousand tasks will each have their own thread and be competing for CPU incurring context switching costs.
- rxJava Schedulers Use Cases
- RxJava之Schedulers详解
- Rxjava Schedulers 使用
- RxJava之调度器(Schedulers)
- Rxjava(2.Schedulers调度器)
- RxJava:Schedulers选择 newThread vs io
- 用Use Cases捕获需求
- Patterns for effective use cases
- Use Cases Patterns and Blueprints
- Use Cases > Storing Log Data
- RxJava开发精要7 - Schedulers-解决Android主线程问题
- 【RxJava Demo分析】(二)Schedulers线程调度器
- Levels of Use Cases(form uml distilled)
- 读书笔记: Use Cases Patterns and Blueprints -- 1
- Use Cases: Requirements in Context, Second Edition
- Aspect Oriented Software Development with Use Cases
- ASAM MCD2D 笔记(1) - ODX use cases
- Why Are Use Cases So Painful?
- SDCard权限设置(结合上一篇)
- Python之中位数
- 矩阵乘法
- centos7学习git笔记
- 动态插入节点方法(一)
- rxJava Schedulers Use Cases
- yii2框架-formatter格式化(九)
- 2015最流行的Android组件、工具、框架大全
- VS中Debug模式和Release模式的区别
- 串口通信帧的同步方法(识别一帧数据的起始结束)
- 51nod 1010 只包含因子2 3 5的数
- eigrp的不等价负载均衡
- 小马哥---高仿苹果6s 主板H339 6571刷机拆机主板图 低配机
- WebStorm开发NodeJS遇到v8debug is not defined的问题