Threads and Coroutines
This chapter promises to be an exciting one as we take a deeper dive into the realm of concurrency in Kotlin. You may recall that in the previous chapter, we touched upon how our application could efficiently handle thousands of requests per second. To illustrate the importance of immutability, we introduced you to the concept of a race condition using two threads.
In this chapter, we’ll extend that understanding and explore the following:
- Looking deeper into threads: How do threads work in Kotlin and what are the advantages and disadvantages of using them?
- Introducing coroutines: What are coroutines and how do suspend functions facilitate them?
- Starting coroutines: How do you launch a new coroutine and what are the different ways to do it?
- Jobs: Understand what jobs are in the context of coroutines and how they help manage concurrent operations.
- Coroutines under the hood: How does the Kotlin compiler handle coroutines...