Android-Universal-Image-Loader
Android-Universal-Image-Loader copied to clipboard
Many java.util.concurrent.RejectedExecutionException in production
I'm using this library about two years. I started to see this exceptions in google analytics (I use it for getting errors from users on production):
Thread: uil-pool-d-3-thread-28, Exception: java.util.concurrent.RejectedExecutionException: Task com.nostra13.universalimageloader.core.LoadAndDisplayImageTask@186d14c rejected from java.util.concurrent.ThreadPoolExecutor@6f47595[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0] at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2014) at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:794) at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1340) at com.nostra13.universalimageloader.core.ImageLoaderEngine$1.run(ImageLoaderEngine.java:78) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818)
First I upgraded UIL to 1.9.5
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
But I keep gettings this exceptions.
My UIL settings:
DisplayImageOptions options = new DisplayImageOptions.Builder()
.cacheInMemory(true)
.bitmapConfig(Bitmap.Config.RGB_565)
.resetViewBeforeLoading(true)
.cacheOnDisk(true)
.build();
config_image = new ImageLoaderConfiguration.Builder(this)
.memoryCache(new LruMemoryCache(50 * 1024 * 1024))
.diskCacheFileCount(10000)
.threadPoolSize(5)
.defaultDisplayImageOptions(options)
.build();
I use it in some ways:
- From resources:
imageLoader.displayImage("drawable://" + String.valueOf(imageRes), toolbarImage);orimageLoader.displayImage("drawable://" + String.valueOf(R.drawable.ic_default_training), toolbarImage); - From server
ImageLoader.getInstance().displayImage(ShopService.API_URL + item.getPhotoUrl(), h.mImageView);
I am getting the same with following configuration: DisplayImageOptions options = new DisplayImageOptions.Builder() .showImageOnLoading(R.mipmap.no_image) .showImageForEmptyUri(R.mipmap.no_image) .showImageOnFail(R.mipmap.no_image) .cacheInMemory(true).cacheOnDisk(true) .imageScaleType(ImageScaleType.IN_SAMPLE_INT) .bitmapConfig(Bitmap.Config.RGB_565).build();
final int memClass = ((ActivityManager) getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
final int cacheSize = 1024 * 1024 * memClass / 4;
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this)
.threadPriority(Thread.MAX_PRIORITY)
.memoryCacheSize(cacheSize)
.diskCache(new UnlimitedDiskCache(StorageUtils.getCacheDirectory(this), null))
.diskCacheFileNameGenerator(new Md5FileNameGenerator())
.defaultDisplayImageOptions(options)
.tasksProcessingOrder(QueueProcessingType.LIFO)
.build();
ImageLoader.getInstance().init(config);