修复 线程重启,导致进度错误的问题 https://github.com/AriaLyy/Aria/issues/145
This commit is contained in:
@@ -133,6 +133,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
|
|||||||
synchronized (AriaManager.LOCK) {
|
synchronized (AriaManager.LOCK) {
|
||||||
mChildCurrentLocation += len;
|
mChildCurrentLocation += len;
|
||||||
STATE.CURRENT_LOCATION += len;
|
STATE.CURRENT_LOCATION += len;
|
||||||
|
//mIncrement += len;
|
||||||
if (System.currentTimeMillis() - mLastSaveTime > 5000) {
|
if (System.currentTimeMillis() - mLastSaveTime > 5000) {
|
||||||
mLastSaveTime = System.currentTimeMillis();
|
mLastSaveTime = System.currentTimeMillis();
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@@ -223,7 +224,8 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
|
|||||||
mFailNum++;
|
mFailNum++;
|
||||||
Log.w(TAG,
|
Log.w(TAG,
|
||||||
"任务【" + mConfig.TEMP_FILE.getName() + "】thread__" + mConfig.THREAD_ID + "__正在重试");
|
"任务【" + 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;
|
mConfig.START_LOCATION = retryLocation;
|
||||||
AbsThreadTask.this.run();
|
AbsThreadTask.this.run();
|
||||||
}
|
}
|
||||||
|
@@ -42,6 +42,8 @@ class FtpThreadTask extends AbsFtpThreadTask<DownloadEntity, DownloadTaskEntity>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override public void run() {
|
@Override public void run() {
|
||||||
|
//当前子线程的下载位置
|
||||||
|
mChildCurrentLocation = mConfig.START_LOCATION;
|
||||||
FTPClient client = null;
|
FTPClient client = null;
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
BufferedRandomAccessFile file = null;
|
BufferedRandomAccessFile file = null;
|
||||||
@@ -72,8 +74,7 @@ class FtpThreadTask extends AbsFtpThreadTask<DownloadEntity, DownloadTaskEntity>
|
|||||||
file.seek(mConfig.START_LOCATION);
|
file.seek(mConfig.START_LOCATION);
|
||||||
byte[] buffer = new byte[mBufSize];
|
byte[] buffer = new byte[mBufSize];
|
||||||
int len;
|
int len;
|
||||||
//当前子线程的下载位置
|
|
||||||
mChildCurrentLocation = mConfig.START_LOCATION;
|
|
||||||
while ((len = is.read(buffer)) != -1) {
|
while ((len = is.read(buffer)) != -1) {
|
||||||
if (STATE.isCancel) break;
|
if (STATE.isCancel) break;
|
||||||
if (STATE.isStop) break;
|
if (STATE.isStop) break;
|
||||||
|
@@ -48,6 +48,8 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
|
|||||||
HttpURLConnection conn = null;
|
HttpURLConnection conn = null;
|
||||||
BufferedInputStream is = null;
|
BufferedInputStream is = null;
|
||||||
BufferedRandomAccessFile file = null;
|
BufferedRandomAccessFile file = null;
|
||||||
|
//当前子线程的下载位置
|
||||||
|
mChildCurrentLocation = mConfig.START_LOCATION;
|
||||||
try {
|
try {
|
||||||
URL url = new URL(CommonUtil.convertUrl(mConfig.URL));
|
URL url = new URL(CommonUtil.convertUrl(mConfig.URL));
|
||||||
conn = ConnectionHelp.handleConnection(url);
|
conn = ConnectionHelp.handleConnection(url);
|
||||||
@@ -78,8 +80,6 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
|
|||||||
file.seek(mConfig.START_LOCATION);
|
file.seek(mConfig.START_LOCATION);
|
||||||
byte[] buffer = new byte[mBufSize];
|
byte[] buffer = new byte[mBufSize];
|
||||||
int len;
|
int len;
|
||||||
//当前子线程的下载位置
|
|
||||||
mChildCurrentLocation = mConfig.START_LOCATION;
|
|
||||||
while ((len = is.read(buffer)) != -1) {
|
while ((len = is.read(buffer)) != -1) {
|
||||||
if (STATE.isCancel) break;
|
if (STATE.isCancel) break;
|
||||||
if (STATE.isStop) break;
|
if (STATE.isStop) break;
|
||||||
|
@@ -44,6 +44,8 @@ class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UploadTaskEntity> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override public void run() {
|
@Override public void run() {
|
||||||
|
//当前子线程的下载位置
|
||||||
|
mChildCurrentLocation = mConfig.START_LOCATION;
|
||||||
FTPClient client = null;
|
FTPClient client = null;
|
||||||
BufferedRandomAccessFile file = null;
|
BufferedRandomAccessFile file = null;
|
||||||
try {
|
try {
|
||||||
@@ -56,8 +58,6 @@ class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UploadTaskEntity> {
|
|||||||
+ ",结束位置:"
|
+ ",结束位置:"
|
||||||
+ mConfig.END_LOCATION
|
+ mConfig.END_LOCATION
|
||||||
+ "】");
|
+ "】");
|
||||||
//当前子线程的下载位置
|
|
||||||
mChildCurrentLocation = mConfig.START_LOCATION;
|
|
||||||
client = createClient();
|
client = createClient();
|
||||||
if (client == null) return;
|
if (client == null) return;
|
||||||
initPath();
|
initPath();
|
||||||
|
@@ -5,7 +5,7 @@
|
|||||||
<download>
|
<download>
|
||||||
|
|
||||||
<!--设置下载线程,线程下载数改变后,新的下载任务才会生效,如果任务大小小于1m,该设置也不会生效-->
|
<!--设置下载线程,线程下载数改变后,新的下载任务才会生效,如果任务大小小于1m,该设置也不会生效-->
|
||||||
<threadNum value="3"/>
|
<threadNum value="1"/>
|
||||||
|
|
||||||
<!--设置下载队列最大任务数, 默认为2-->
|
<!--设置下载队列最大任务数, 默认为2-->
|
||||||
<maxTaskNum value="1"/>
|
<maxTaskNum value="1"/>
|
||||||
|
@@ -35,9 +35,8 @@ import java.io.File;
|
|||||||
* Ftp下载测试
|
* Ftp下载测试
|
||||||
*/
|
*/
|
||||||
public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding> {
|
public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding> {
|
||||||
private final String URL = "ftp://d:d@dygodj8.com:12311/[电影天堂www.dy2018.com]光辉岁月BD韩语中字.rmvb";
|
|
||||||
//private final String URL = "ftp://192.168.1.9:21/下载/AriaPrj.zip";
|
//private final String URL = "ftp://192.168.1.9:21/下载/AriaPrj.zip";
|
||||||
//private final String URL = "ftp://192.168.1.9:21/下载/[电影天堂www.dy2018.com]赛车总动员3BD中英双字.mp4";
|
private final String URL = "ftp://192.168.1.9:21/下载/[电影天堂www.dy2018.com]赛车总动员3BD中英双字.mp4";
|
||||||
|
|
||||||
@Override protected void init(Bundle savedInstanceState) {
|
@Override protected void init(Bundle savedInstanceState) {
|
||||||
super.init(savedInstanceState);
|
super.init(savedInstanceState);
|
||||||
|
Reference in New Issue
Block a user