Reputation: 1385
I want to create a thread pool in Kotlin. I have been searching for hours in the internet and I can not get a single example. Can anyone provide examples. thank you.
Upvotes: 17
Views: 18219
Reputation: 1385
val executor = Executors.newFixedThreadPool(5)
for (i in 0..9) {
val worker = Runnable { println("Hello this is thread " + i) }
executor.execute(worker)
}
executor.shutdown()
executor.awaitTermination(1, TimeUnit.HOURS)
println("Finished all threads")
Upvotes: 22