当前位置:网站首页>2.6 preliminary cognition of synergetic couroutines
2.6 preliminary cognition of synergetic couroutines
2022-07-03 12:14:00 【schr03p】
coroutines Couroutines My initial understanding
One 、 What is? Kotlin coroutines
coroutines (Coroutine) Is the collaborative program , and Kotlin Synergy is a process based on Java Thread API Packaged toolkit , Help us easily write complex concurrent code
kotlin Compared with thread pool , There is no performance advantage
Non blocking suspension is nothing special ,java Sub threads are also non blocking
If you are familiar with Rxjava, Compare the process again , You will find that the synergy ratio Rxjava It works
Solve the problem of callback to hell
Two 、Coroutines The advantages of 、 characteristic
Light weight
The essence , Convenient for multi-threaded development
Thread pool
Network library support , Light and elegant
3、 ... and 、 Quick view of knowledge points
Common coprocessing functions
| Function name | Brief features |
|---|---|
| runBlocking:T | Internal coordination process started , Meeting Blocking Current thread , until block The execution of the coordination process in the end . Common methods of calling coprocessor functions |
| launch:Job | The most commonly used way to start the process ; return Job object , operational Job; It won't block Current calling thread ; |
| async:Deferred | Be similar to launch, Start asynchronous ; Can be used for multiple concurrency ;await Consolidated results |
CoroutineContext
Dispatchers.Main、
Dispatchers.IO、Dispatchers.default( Execute... In the process pool )
Dispatchers.Unconfined
LauncherMode
Mode Value default Default , Execute the program immediately lazy Execute when needed atomic Execute now , Operation atomization , Cannot cancel before starting undispatched Execute immediately on the current thread , Until the first one suspend call suspend function
suspend function Will bring the whole coroutines Hang up , Not just this suspend function , That is to say a coroutines There are multiple Suspend function when , They are executed sequentially
resume
The call stack
Scope
UI
ViewModel
Four 、 The way to deal with asynchrony
Threads
Commonly used , Simple and convenient
resource consumption
The number is limited
Platform support (JS There is no thread )
Inconvenient to debug
Callback
Hierarchical call
Multiple nesting
Error handling is troublesome
Futures、 Promise
Programming elegance
Change the programming method , Such as exception handling and circulation , Invalid in
Api Study , Platform differences
Return type qualification promise
Exception handling is complex
Rx Reactive expansion
The design idea of observable flow , Elegant and convenient
The learning curve
Api
Behavior is hard to estimate
coroutines
studies of the Book of Changes 、 Easy to use
jetpack,kotlin,aac,scope/vvm
Learning cost
边栏推荐
- Deploying WordPress instance tutorial under coreos
- temp
- Develop plug-ins for idea
- 347. Top k high frequency elements
- OPenGL 基本知识(根据自己理解整理)
- (构造笔记)从类、API、框架三个层面学习如何设计可复用软件实体的具体技术
- Fluent: Engine Architecture
- [combinatorics] permutation and combination (summary of permutation and combination content | selection problem | set permutation | set combination)
- previous permutation lintcode51
- 网络通讯之Socket-Tcp(一)
猜你喜欢

(构造笔记)ADT与OOP
![[official MySQL document] deadlock](/img/2d/04e97d696f20c2524701888ea9cd10.png)
[official MySQL document] deadlock

OPenGL 基本知识(根据自己理解整理)

New features of ES6
![[learning notes] DP status and transfer](/img/5e/59c64d2fe08b89fba2d7e1e6de2761.png)
[learning notes] DP status and transfer

Duplicate numbers in the array of sword finger offer 03

vulnhub之Ripper

Shutter: overview of shutter architecture (excerpt)

Flutter 退出登录二次确认怎么做才更优雅?

Socket TCP for network communication (I)
随机推荐
Shell: basic learning
PHP export word method (one MHT)
vulnhub之tomato(西红柿)
Dart: about grpc (I)
php 获取文件夹下面的文件列表和文件夹列表
C language improvement article (wchar_t) character type
Solution to the second weekly test of ACM intensive training of Hunan Institute of technology in 2022
Master and backup role election strategy in kept
(構造筆記)從類、API、框架三個層面學習如何設計可複用軟件實體的具體技術
Wechat applet development - page Jump transfer parameters
在网上炒股开户可以吗?资金安全吗?
Solutions to the failure of installing electron
【附下载】密码获取工具LaZagne安装及使用
023 ([template] minimum spanning tree) (minimum spanning tree)
OpenGL 索引缓存对象EBO和线宽模式
Redis notes 01: Introduction
Groovy test class and JUnit test
Systemverilog-- OOP--对象的拷贝
vulnhub之Nagini
Slf4j log facade