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
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