当前位置:网站首页>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
边栏推荐
- Vulnhub's Tomato (tomato)
- 网络通讯之Socket-Tcp(一)
- DEJA_ Vu3d - cesium feature set 053 underground mode effect
- Deploying WordPress instance tutorial under coreos
- 023(【模板】最小生成树)(最小生成树)
- Introduction to the implementation principle of rxjs observable filter operator
- laravel 时区问题timezone
- Vulnhub's cereal
- Dart: about grpc (I)
- OPenGL 基本知识(根据自己理解整理)
猜你喜欢

Socket TCP for network communication (I)

Download address and installation tutorial of vs2015

Shutter widget: centerslice attribute

Vulnhub geminiinc

Vulnhub's cereal

Qt OpenGL 纹理贴图

【mysql专项】读锁和写锁

Xiaopeng P7 hit the guardrail and the airbag did not pop up. The official responded that the impact strength did not meet the ejection requirements

PHP导出word方法(一mht)

"Jianzhi offer 04" two-dimensional array search
随机推荐
vulnhub之Ripper
Shutter widget: centerslice attribute
Download address and installation tutorial of vs2015
[combinatorics] permutation and combination (summary of permutation and combination content | selection problem | set permutation | set combination)
LeetCode 0556.下一个更大元素 III - 4步讲完
Laravel time zone timezone
Pragma pack syntax and usage
Unicode encoding table download
Dart: self study system
Qt OpenGL 旋转、平移、缩放
Vulnhub's Tomato (tomato)
Vulnhub geminiinc V2
[official MySQL document] deadlock
PHP export word method (one MHT)
Ripper of vulnhub
Unity3d learning notes 5 - create sub mesh
OpenGL 索引缓存对象EBO和线宽模式
Test classification in openstack
Introduction to concurrent programming (II)
vulnhub之tomato(西红柿)