androidvirtual-threadsproject-loom

Is it possible to use virtual threads from Kotlin in an Android project as of current date?


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:

Thanks!


Solution

  • 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.