Issue
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.
Solution
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")
Answered By - Methnani Bilel
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.