当前位置:网站首页>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
边栏推荐
- (construction notes) grasp learning experience
- OpenGL draws colored triangles
- Php Export word method (One MHT)
- OpenGL index cache object EBO and lineweight mode
- OpenGL shader use
- Laravel time zone timezone
- 手机号码变成空号导致亚马逊账号登陆两步验证失败的恢复网址及方法
- Differences between MySQL Union and union all
- Fundamentals of concurrent programming (III)
- Shutter: overview of shutter architecture (excerpt)
猜你喜欢

During FTP login, the error "530 login incorrect.login failed" is reported

(construction notes) ADT and OOP

4000字超详解指针

Vulnhub's Tomato (tomato)

【附下载】密码获取工具LaZagne安装及使用

(构造笔记)ADT与OOP

LeetCode 0556.下一个更大元素 III - 4步讲完

PHP export word method (one MHT)

为什么我的mysql容器启动不了呢

Introduction to the implementation principle of rxjs observable filter operator
随机推荐
145. Post order traversal of binary tree
Basic knowledge of OpenGL (sort it out according to your own understanding)
【mysql官方文档】死锁
ES6新特性
Flutter Widget : KeyedSubtree
Flutter Widget : Flow
Integer string int mutual conversion
PHP导出word方法(一phpword)
Php Export word method (One MHT)
Socket TCP for network communication (I)
Flutter: self study system
Solution à la défaillance de l'installation d'Electron
temp
Summary of development issues
OpenGL shader use
Talk about the state management mechanism in Flink framework
Is BigDecimal safe to calculate the amount? Look at these five pits~~
QT OpenGL texture map
Capturing and sorting out external Fiddler -- Conversation bar and filter [2]
Ripper of vulnhub