https://blog.csdn.net/izard999/article/details/8552681
本人亲笔原创, 欢迎转载, 但是转载请注明出处http://blog.csdn.net/izard999/article/details/8552681 谢谢
我们的Android项目前些天把图片下载放到线程池去开线程做了,一般的界面是没有什么问题,但是数据量大一点的ListView有的时候就会抛RejectedExecutionException.
Google了一些资料,其实说的也还可以,就是举了些例子. 大致看了之后, 我还是决定自己追源码!
首先我调用Executors创建的线程池出来的对象是ThreadPoolExecutor,ScheduledThreadPoolExecutor,DelegatedExecutorService这三个类中的一个! 而ScheduledThreadPoolExecutor是ThreadPoolExecutor的子类, DelegatedExecutorService是对ExecutorService进行一层包装.
今天我们这里不讨论每一种线程池是干什么的, 只讨论RejectedExecutionException的原由, 所以我只拿ThreadPoolExecutor这个作为例子说了.
当我们调用Executors.newFixedThreadPool(int nThreads )时会创建一个线程池给我. 源码这个方法的