Kotlin Executors线程池newSingleThreadExecutor单线程
import java.util.concurrent.Executors
fun main() {
val mExecutorService = Executors.newSingleThreadExecutor()
for (i in 1..5) {
mExecutorService.execute {
println("seq-$i tid:${Thread.currentThread().threadId()} ->start")
Thread.sleep(1000)
println("seq-$i tid:${Thread.currentThread().threadId()} <-end")
}
}
mExecutorService.shutdown()
}
seq-1 tid:22 ->start
seq-1 tid:22 <-end
seq-2 tid:22 ->start
seq-2 tid:22 <-end
seq-3 tid:22 ->start
seq-3 tid:22 <-end
seq-4 tid:22 ->start
seq-4 tid:22 <-end
seq-5 tid:22 ->start
seq-5 tid:22 <-endProcess finished with exit code 0
文章来源地址https://www.toymoban.com/news/detail-650752.html
Java线程池:ExecutorService,Executors_executorservice线程池_zhangphil的博客-CSDN博客简单的Java线程池可以从Executors.newFixedThreadPool( int n)获得。此方法返回一个线程容量为n的线程池。然后ExecutorService的execute执行之。现给出一个示例。package zhangphil.executorservice;import java.util.concurrent.ExecutorService;import j_executorservice线程池https://blog.csdn.net/zhangphil/article/details/43898637ScheduledThreadPoolExecutor周期性执行线程任务scheduleAtFixedRate_zhangphil的博客-CSDN博客ScheduledThreadPoolExecutor周期性执行线程任务scheduleAtFixedRate ScheduledThreadPoolExecutor mScheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1); mScheduledThreadPoolExecutor.sched...https://blog.csdn.net/zhangphil/article/details/80735215文章来源:https://www.toymoban.com/news/detail-650752.html
到了这里,关于Kotlin Executors线程池newSingleThreadExecutor单线程的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!