search

Home  >  Q&A  >  body text

java - Android多线程下载速度很慢,为什么市面上的应用市场下载速度却很快

自己写应用市场,用多线程下载apk文件,可下载速度却很慢(不是网速的问题),用市面上的应用市场下文件却很快,是为什么?
accessFile = new RandomAccessFile(file, "rwd");
accessFile.seek(startPos + completeSize);// 设置从哪个位置写入数据
inputStream = connection.getInputStream();
byte[] buffer = new byte[4096];
int length = -1;
while ((length = inputStream.read(buffer)) != -1) {

    // 写入数据
    accessFile.write(buffer, 0, length);
    // 累加已经下载的长度
    completeSize = completeSize + length;

}
这里面的byte[4096]设置成byte[4096*1000],可每次最多还是只读了8192是为什么???

迷茫迷茫2802 days ago3142

reply all(1)I'll reply

  • ringa_lee

    ringa_lee2017-04-18 09:09:53

    You may have a problem with multi-threading. You can log and see the amount of data downloaded by each thread

    reply
    0
  • Cancelreply