I'm reading a book about Kotlin coroutines which explains the possibility to create a custom dispatcher which schedules virtual threads and also provides code to test the performance.
Is it possible to run say code like Thread.startVirtualThread
from an Android project using Kotlin? What are the things that I need to setup (currently the compiler reports this method doesn't exist)? I couldn't find anything about Android and Loom despite doing some searching on the web, also all examples of setting --enable-preview
are for IntelliJ Idea. Pardon me if the answer is obvious, but I'm new to mobile development and Kotlin and I'm curious given the performance benefits of virtual threads.
I tried:
--enable-preview
in Settings -> Build, Execution, Deployment -> Gradle-Android Compiler -> Command-line Options from Android StudiosourceCompatibility
and targetCompatibility
to Java 21 in GradlejvmTarget
to 21 in GradleThanks!
Is it possible to run say code like
Thread.startVirtualThread
from an Android project using Kotlin?
As of December 2024, startVirtualThread()
is not part of the Android SDK edition of the Thread
class. Until the Android SDK offers it, you cannot use it in an Android projecet.