Skip to content
TopicTracker
From HackerNewsView original
TranslationTranslation

A million LOC from Java threads to Kotlin coroutines, by rewriting 3 files

The article describes a real-world case study of migrating one million lines of code from Java threads to Kotlin coroutines at a large company. The migration was achieved by rewriting just three core files: a custom Thread, a ThreadPoolExecutor, and a scheduling class. This approach allowed the entire codebase to switch to structured concurrency without modifying each individual usage.

Background

- Kotlin coroutines are a modern concurrency framework for the JVM (and Android) that allows writing asynchronous code in a sequential style, avoiding the complexity of raw Java threads and callbacks. - Java threads are the older, OS-level concurrency primitive — each thread consumes significant memory (~1MB stack) and can lead to complex, error-prone code when managing many concurrent tasks. - The article describes a real migration at a company with a large Android codebase (1M+ lines), showing how a well-designed "abstraction layer" (custom wrappers around threading) can be rewritten in one place, allowing the entire app to switch from threads to coroutines without modifying most files. - "Three files" refers to the core abstraction files that all other code depended on — by updating those, the migration was effectively done for the whole project. - This is relevant because Android development has largely moved to coroutines; sharing a concrete, large-scale migration strategy is valuable for engineering teams still on older threading models.