There is an article in the Android Development guide on how to load pictures more efficiently, with the address https://developer.android.com/training/displaying-bitmaps/ Index.html, this article describes in detail how to load high-definition graphics to memory, while avoiding system report oom problem, the article is very good, the sample program can also run directly. During a minor version upgrade of our project, we tried to load the picture using an Open-source project Afinal (bitmapfun) on git, but a problem was found in the test, the new picture loader (Bitmapfun) Imagedownloader than before used a lot of slow, especially in the network situation is bad, it is a pit dad, such as 5s clock is less, and generally to wait for 10s, the eldest brother to find me, said this picture loading does not come out ah, too slow. Holy cow, no, this joke is a little bit big, it's a lot slower to take.
Then began debugging work, I began to think is not the network download part of the same, before using the httpclient, now bitmapfun with the url.openconnection, decisively replaced HttpClient method before, feel better ( In fact, it is their own psychological mischief), try again, find sometimes fast, sometimes slow, contrast before, the previous picture has been very stable, do not appear this Ah, and then think of a way, in the project to find two pages, one with the previous imagedownload load, and the other with bitmapfun loading , and then put each period (can be divided into 3 sections bar, 1 is from the memory cache, 2 from the Network load, 3 is stored to the internal cache and SDcard cache) time to print out the contrast, found that it is really bitmapfun download this piece (Processbitmap method) inside the most time-consuming, This part of the code, see Sync Lock, it should be him, I see, no problem ah, only a small block, should be to prevent the cache is not initialized, over ... Looking down again, frequent IO operations on the sdcard, yes, it should be here, the method just repeat, segmented printing time-consuming, a look at the results, Tnnd, occupy the longest time is actually wait operation, that is, the lock waiting, and then look at the code, double-click the scope of the lock, found that the basic is The entire download process is locked synchronously, this Nima, too pit Dad, a picture in the download time, the other will have to wait there, that the new 3 core threads, by you synchronized into one, I said how to see this loading pictures so neat, one by two.
Found the problem, ask why, he did this reason is what, in fact, for that Disklrucache log file, not allow multiple threads to operate at the same time, otherwise the log will be confused, there is no way to statistics which file is the longest not used. I want to try to change the scope of the lock, found a bit difficult, because the download process of the log file operation is too frequent, which Daniel has a good way to tell me, I appreciate.
A bit of advice on using Bitmapfun or afinal, the key to Disklrucache slow is that the requirements for log files (journal files in the directory) are too high, and the function of log files is to record the number of visits to each file, So it writes every read and write to the log file, so that it can more accurately count the longest unused files, but the price is too high (frequent IO operations and sync locks), remember the last version of the bitmapfun is not log files, Directly from the program Access SDcard cache to start computing access time, in fact, this is more appropriate, better performance. So if you use this sample program to load pictures, the best way is to use the previous version of the Disklrucache or find ways to implement log file records, there are better ways to include log file recording method, remember to tell me Oh!
Attached: The old version of the Bitmapfun, do not want to rewrite their own file lock students can put the file cache into the inside. Click the file to download