Concurrency in Kotlin: From Basics to Advanced Patterns
Concurrency in Kotlin: From Basics to Advanced Patterns
Summary:
The book "Concurrency in Kotlin: From Basics to Advanced Patterns" is a comprehensive guide to building fast, responsive, and scalable applications in the Kotlin language. Whether you write in Kotlin for Android, server-side (Ktor, Spring WebFlux), or desktop, this book will help you deeply understand asynchrony and multithreading.
What is this book about?
The book covers the full path from basic concepts to complex concurrency programming scenarios. You will learn:
- Concurrency basics — how threads differ from coroutines, how the Dispatcher works, and why coroutines are lighter than threads.
- Kotlin Coroutines — launching, cancellation, structured concurrency, Scopes, Job, and Deferred.
- Thread safety — atomic variables, Mutex, Semaphore, ThreadLocal, and working with shared state.
- Channels — Producer-Consumer, fan-out, fan-in, ticker channels for streaming data.
- Flow and Reactive Streams — cold and hot streams, backpressure, transformation operators, StateFlow, and SharedFlow.
- Advanced patterns — Actor Model, Supervisor, CoroutineExceptionHandler, parallel processing with mapAsync and flatMapMerge.
- Testing concurrent code — runTest, TestDispatcher, mock coroutines, and debugging data races.
Who is this book for?
- Kotlin developers (Android, Backend, Multiplatform) who want to write asynchronous code without blocking.
- Juniors and mid-level developers looking to systematize their knowledge of coroutines and multithreading.
- Programmers transitioning from Java (CompletableFuture, Thread) to modern Kotlin.
- Anyone who wants to avoid race conditions, deadlocks, and memory leaks in concurrent applications.
What will you learn?
- How to properly launch and cancel coroutines without causing leaks.
- How to choose between Dispatchers.Default, IO, Main, and Unconfined.
- How to build reactive chains with Flow and handle errors in streams.
- How to test asynchronous code using virtual time.
- How to write high-load servers and Android applications without lag.
The book contains dozens of practical examples ready for use in real projects. After reading it, you will be able to confidently design concurrent architectures and optimize the performance of your code.
Note: The book is intended for readers already familiar with Kotlin syntax. If you are just starting to learn the language, it is recommended to first complete a basic course.
Recommendations
Testing Java Applications: From Unit Tests to Integration Scenarios
Refactoring Kotlin Code: Improving Architecture and Performance
Testing C++ Applications: From Unit Tests to Integration Testing
Testing C++ Applications: From Unit Tests to Integration Coverage
Writing an Interpreter in Go
Too Many Linked Lists