首页 > 其他分享 >Android中使用线程池

Android中使用线程池

时间:2023-02-21 16:13:46浏览次数:29  
标签:java Executors 线程 使用 Android ExecutorService pool

ArchTaskExecutor 是androidx封装的线程接口
接口内部是 调用 Executors 开启4个线程的java线程池 Executors.newFixedThreadPool(4, new ThreadFactory() {
切换到子线程或者主线程
ArchTaskExecutor.getInstance().executeOnDiskIO
ArchTaskExecutor.getInstance().executeOnMainThread

java Executors 线程池管理类
1.固定大小的线程池
ExecutorService pool = Executors.newFixedThreadPool(5)
2.可变尺寸的线程池
ExecutorService pool = Executors.newCachedThreadPool();
3.单任务线程池
ExecutorService pool = Executors.newSingleThreadExecutor()
4.延迟连接池
ScheduledExecutorService pool = Executors.newScheduledThreadPool(2)

标签:java,Executors,线程,使用,Android,ExecutorService,pool
From: https://www.cnblogs.com/adamli/p/17141350.html

相关文章