Concurrency/Parallelism Options For Kotlin?


#1

Been looking at concurrency/parallelism options for Kotlin lately (for desktop and server side development) and was wondering what concurrency/parallelism options are available. My knowledge of concurrency/parallelism is very limited with only knowing about threads, Java streaming API, and the UI/background threading technique (for desktop development).

Is there a good website to visit that properly explains all the different concurrency/parallelism options (only the major ones) in a plain English way?

Can be very confusing to get your head around all the different concurrency/parallelism options, and the general concepts in terms of how they all tie in together.


#2

The set of options available for Kotlin is exactly the same as in Java. Because of that, you won’t find a Kotlin-specific description, but any articles covering Java will apply to Kotlin as well.


#3

You also might be interested in Kotlin coroutines which are coming as an experimental feature in Kotlin 1.1. You can read the informal description of their design and use cases here: https://github.com/Kotlin/kotlin-coroutines/blob/master/kotlin-coroutines-informal.md


#4

Look at Quasar.

I hope that Quasar + Kotlin 1.1 + JVM 1.9 will become a great team.


#5

Don’t forget RxJava. Reactive programming is a powerful way to handle concurrency and parallelism, as well as make programming easier in general.


#6

Very good suggestions coming through on concurrency options. Some thoughts on these options:

  • Quasar - Easy to use API, decent documentation, has some Kotlin APIs, difficult to deploy with the Java Agent requirement, doesn’t have Android support, solely focused on concurrency/parallelism
  • RxJava - Well supported on Android with plenty of articles/videos, very high learning curve, there is a Kotlin version available (RxKotlin), not widely used outside of Android, mainly focussed on event processing
  • Kotlin Coroutines - Builtin support in Kotlin 1.1 (will be experimental), has no default implementation but provides a low level API to implement a high level concurrency model, provides some general performance advantages?, implementations provided (by JetBrains/Kotlin community) for some concurrency models (some are Android specific)

#7

One possible option for concurrency is Vert.x which can be used standalone with its Agent concurrency model (known as the Event Bus). Important to note that Vert.x isn’t solely focused on concurrency as it is a toolkit for creating reactive applications for the JVM, and has very good documentation. Kotlin support is in the works (currently synced with the latest stable Vert.x version), and should hopefully be officially supported soon.