thhh
03/21/2021, 9:56 AMimport kotlinx.coroutines.*
fun main() {
repeat(3) {
GlobalScope.launch {
println("Hi from ${Thread.currentThread()}")
}
}
}
on IntelliJ idea 2020.3.2:
The output is this:
6:14:05 PM: Executing task 'Coroutines_multipleKt.main()'...
> Task :wrapper
BUILD SUCCESSFUL in 184ms
1 actionable task: 1 executed
> Task :compileKotlin
> Task :compileJava NO-SOURCE
> Task :processResources NO-SOURCE
> Task :classes UP-TO-DATE
> Task :Coroutines_multipleKt.main()
BUILD SUCCESSFUL in 712ms
2 actionable tasks: 2 executed
6:14:06 PM: Task execution finished 'Coroutines_multipleKt.main()'.
But on Kotlin Playground I get the output that is expected:
Hi from Thread[DefaultDispatcher-worker-1 @coroutine#1,5,main] Hi from Thread[DefaultDispatcher-worker-1 @coroutine#2,5,main] Hi from Thread[DefaultDispatcher-worker-1 @coroutine#3,5,main]
What am I doing wrong?
Why doesn't IntelliJ produce the output as desired?
I have added an image: https://i.imgur.com/N9WjEZz.png▾
https://i.imgur.com/1unP2hY.gif▾
fun main() {
repeat(3) {
GlobalScope.launch {
println("Hi from ${Thread.currentThread()}")
}
}
Thread.sleep(2000L)
}