Tag: multithreading

使用Kotlin协程的multithreading

我正在用Kotlin Coroutines进行试验,并有如下代码: fun main(args: Array) = runBlocking { val cores = Runtime.getRuntime().availableProcessors() println(“number of cores: $cores”) val jobs = List(10) { async(CommonPool) { delay(100) println(“async #$it on thread ${Thread.currentThread().name}”) } } jobs.forEach { it.join() } } 这是我的输出: number of cores: 4 async number:0 on thread ForkJoinPool.commonPool-worker-2 async number:2 on thread ForkJoinPool.commonPool-worker-3 async number:3 on thread […]