0
我想在Kotlin中創建線程池。我一直在互聯網上搜索幾個小時,我無法得到一個例子。任何人都可以舉例。謝謝。如何在Kotlin中創建線程池
我想在Kotlin中創建線程池。我一直在互聯網上搜索幾個小時,我無法得到一個例子。任何人都可以舉例。謝謝。如何在Kotlin中創建線程池
val executor = Executors.newFixedThreadPool(5)
for (i in 0..9) {
val worker = Runnable { println("Hello this is thread " + i) }
executor.execute(worker)
}
executor.shutdown()
while (!executor.isTerminated) {
}
println("Finished all threads")
像在Java代碼中一樣使用標準ThreadPool。 – voddan