Android多线程下载如何设置线程数
ringa_lee
ringa_lee 2017-04-17 13:46:42
0
5
896

在Android中进行多线程下载一个文件时,线程数要根据什么来设置,是根据手机的cpu核心数来设置吗?

ringa_lee
ringa_lee

ringa_lee

reply all(5)
PHPzhong

It is impossible to set based on the number of CPU cores. What if the number of threads in a quad-core CPU can only be 4 at most? There are definitely more.
When writing, you can set the maximum number of concurrent threads yourself, Executors.newFixedThreadPool(num);

大家讲道理

Generally, it depends on how many cores and threads the CPU has. After all, the performance of a mobile phone cannot be compared with that of a computer. It must be set according to the performance of the mobile phone itself.

洪涛

It has nothing to do with CPU. For this kind of multi-threaded download or multi-threaded IO, the bottleneck is not the CPU, but the response speed of the IO asynchronous callback. This is not the same as concurrent compilation. It doesn't matter if you open multiple threads, the memory overhead won't be much.

迷茫

It is said that setting the number of threads to the number of CPUs + 1 would be better

左手右手慢动作

Not only should you look at the number of CPU cores, but also the proportions of the CPU calculation part and the IO operation part in your operation to see where the bottleneck is
If you don’t mind it, you can use systrace to observe it Here’s the specific execution process

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template