When running on the JVM, if we need to run things concurrently we can use Java APIs or Kotlin coroutines. In this episode we implement a parallelMap operation using streams, raw threads, a threadpool with futures, and coroutines. The results may surprise you!
This is part 55 of an exploration of where a Test Driven Development implementation of the Gilded Rose stock control system might take us in Kotlin. You can see the whole series as a playlist
• All Gilded Rose Episodes
and the code on GitHub
https://github.com/dmcg/gilded-rose-tdd
There has been some discussion on Reddit about my use of AtomicReference in the threads implementation. I'm persuaded that any old non-thread-safe holder would do, and would probably be more performant - / j089h0d
The next episode ( • Threads vs Coroutines - ParallelMap P... ) measures the performance of the implementations.
If you like this, you’ll probably like the book Java to Kotlin, A Refactoring Guidebook
http://java-to-kotlin.dev , and maybe join Nat Pryce and me on our TDD workshop at KotlinConf in April next year https://kotlinconf.com/workshops/
Watch video Threads vs Coroutines - ParallelMap in Kotlin online without registration, duration hours minute second in high quality. This video was added by user Pairing with Duncan 02 December 2022, don't forget to share it with your friends and acquaintances, it has been viewed on our site 2,094 once and liked it 76 people.