修复 线程重启,导致进度错误的问题 https://github.com/AriaLyy/Aria/issues/145

This commit is contained in:
AriaLyy
2017-10-24 22:04:19 +08:00
parent 29bcf0aa15
commit 3a3667f214
6 changed files with 12 additions and 10 deletions

View File

@@ -133,6 +133,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
synchronized (AriaManager.LOCK) {
mChildCurrentLocation += len;
STATE.CURRENT_LOCATION += len;
//mIncrement += len;
if (System.currentTimeMillis() - mLastSaveTime > 5000) {
mLastSaveTime = System.currentTimeMillis();
new Thread(new Runnable() {
@@ -223,7 +224,8 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
mFailNum++;
Log.w(TAG,
"任务【" + mConfig.TEMP_FILE.getName() + "】thread__" + mConfig.THREAD_ID + "__正在重试");
final long retryLocation = mChildCurrentLocation;
final long retryLocation =
mChildCurrentLocation == 0 ? mConfig.START_LOCATION : mChildCurrentLocation;
mConfig.START_LOCATION = retryLocation;
AbsThreadTask.this.run();
}

View File

@@ -42,6 +42,8 @@ class FtpThreadTask extends AbsFtpThreadTask<DownloadEntity, DownloadTaskEntity>
}
@Override public void run() {
//当前子线程的下载位置
mChildCurrentLocation = mConfig.START_LOCATION;
FTPClient client = null;
InputStream is = null;
BufferedRandomAccessFile file = null;
@@ -72,8 +74,7 @@ class FtpThreadTask extends AbsFtpThreadTask<DownloadEntity, DownloadTaskEntity>
file.seek(mConfig.START_LOCATION);
byte[] buffer = new byte[mBufSize];
int len;
//当前子线程的下载位置
mChildCurrentLocation = mConfig.START_LOCATION;
while ((len = is.read(buffer)) != -1) {
if (STATE.isCancel) break;
if (STATE.isStop) break;

View File

@@ -48,6 +48,8 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
HttpURLConnection conn = null;
BufferedInputStream is = null;
BufferedRandomAccessFile file = null;
//当前子线程的下载位置
mChildCurrentLocation = mConfig.START_LOCATION;
try {
URL url = new URL(CommonUtil.convertUrl(mConfig.URL));
conn = ConnectionHelp.handleConnection(url);
@@ -78,8 +80,6 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
file.seek(mConfig.START_LOCATION);
byte[] buffer = new byte[mBufSize];
int len;
//当前子线程的下载位置
mChildCurrentLocation = mConfig.START_LOCATION;
while ((len = is.read(buffer)) != -1) {
if (STATE.isCancel) break;
if (STATE.isStop) break;

View File

@@ -44,6 +44,8 @@ class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UploadTaskEntity> {
}
@Override public void run() {
//当前子线程的下载位置
mChildCurrentLocation = mConfig.START_LOCATION;
FTPClient client = null;
BufferedRandomAccessFile file = null;
try {
@@ -56,8 +58,6 @@ class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UploadTaskEntity> {
+ ",结束位置:"
+ mConfig.END_LOCATION
+ "");
//当前子线程的下载位置
mChildCurrentLocation = mConfig.START_LOCATION;
client = createClient();
if (client == null) return;
initPath();