From b82bc1be35f6650f1239e4634ac5cdd051b65f97 Mon Sep 17 00:00:00 2001 From: lijia Date: Fri, 28 Jun 2024 15:21:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=8B=E8=BD=BD=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E7=9A=84=E4=BC=98=E5=85=88=E7=BA=A7=E8=80=83=E8=99=91=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E6=AC=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/nicelee/ui/item/DownloadInfoPanel.java | 3 ++- src/nicelee/ui/thread/DownloadExecutors.java | 12 +++++++++++- src/nicelee/ui/thread/DownloadRunnable.java | 2 +- src/nicelee/ui/thread/DownloadRunnableInternal.java | 5 ++++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/nicelee/ui/item/DownloadInfoPanel.java b/src/nicelee/ui/item/DownloadInfoPanel.java index fc9b8b7a..beaeb525 100644 --- a/src/nicelee/ui/item/DownloadInfoPanel.java +++ b/src/nicelee/ui/item/DownloadInfoPanel.java @@ -251,7 +251,8 @@ public void continueTask() { if (status != StatusEnum.DOWNLOADING && status != StatusEnum.SUCCESS && status != StatusEnum.PROCESSING) { downloader.startTask(); if(!Global.downLoadThreadPool.isShutdown()){ - Global.downLoadThreadPool.execute(new DownloadRunnableInternal(this, System.currentTimeMillis(), true)); + Global.downLoadThreadPool.execute( + new DownloadRunnableInternal(this, System.currentTimeMillis(), true, failCnt)); } } } diff --git a/src/nicelee/ui/thread/DownloadExecutors.java b/src/nicelee/ui/thread/DownloadExecutors.java index 5b818351..fa398566 100644 --- a/src/nicelee/ui/thread/DownloadExecutors.java +++ b/src/nicelee/ui/thread/DownloadExecutors.java @@ -14,9 +14,19 @@ public class DownloadExecutors { @Override public int compare(DownloadRunnableInternal o1, DownloadRunnableInternal o2) { // o1.invokeByContinueTask 为true时优先级更高 + // o1.failCnt 越大优先级更高(为0时特殊考虑) // o1.urlTimestamp 越小优先级更高 if (o1.invokeByContinueTask == o2.invokeByContinueTask) { - return (int) (o1.urlTimestamp - o2.urlTimestamp); + if (o1.failCnt == o2.failCnt) { + return (int) (o1.urlTimestamp - o2.urlTimestamp); + } else { + // 走到这个分支不可能有“开始下载”的任务,failCnt == 0表示人为重新开始任务 + if(o1.failCnt == 0) + return -1; + if(o2.failCnt == 0) + return -1; + return o2.failCnt - o1.failCnt; + } } else { return o1.invokeByContinueTask ? -1 : 1; } diff --git a/src/nicelee/ui/thread/DownloadRunnable.java b/src/nicelee/ui/thread/DownloadRunnable.java index a29a47eb..796d5120 100644 --- a/src/nicelee/ui/thread/DownloadRunnable.java +++ b/src/nicelee/ui/thread/DownloadRunnable.java @@ -127,7 +127,7 @@ public void download() { jpContent.add(downPanel); jpContent.setPreferredSize(new Dimension(1100, 128 * Global.downloadTaskList.size())); if(!Global.downLoadThreadPool.isShutdown()){ - Global.downLoadThreadPool.execute(new DownloadRunnableInternal(downPanel, System.currentTimeMillis(), false)); + Global.downLoadThreadPool.execute(new DownloadRunnableInternal(downPanel, System.currentTimeMillis(), false, 0)); } if(Global.sleepAfterDownloadQuery > 0) { try { diff --git a/src/nicelee/ui/thread/DownloadRunnableInternal.java b/src/nicelee/ui/thread/DownloadRunnableInternal.java index aaac72a6..388e3bbf 100644 --- a/src/nicelee/ui/thread/DownloadRunnableInternal.java +++ b/src/nicelee/ui/thread/DownloadRunnableInternal.java @@ -16,6 +16,7 @@ public class DownloadRunnableInternal implements Runnable { final DownloadInfoPanel downPanel; final long urlTimestamp; final boolean invokeByContinueTask; + final int failCnt; // 下面这些值都可以从 downPanel 直接或者间接获取 final String record; final INeedAV iNeedAV; @@ -30,11 +31,13 @@ public class DownloadRunnableInternal implements Runnable { * @param downPanel 下载任务绑定的UI控件,相关信息可以从这里获取 * @param urlTimestamp 当前下载链接的获取时间 * @param invokeByContinueTask 该线程是否是 “继续任务”, 而不是 “开始任务” + * @param failCnt 在此之前的任务失败次数 */ - public DownloadRunnableInternal(DownloadInfoPanel downPanel, long urlTimestamp, boolean invokeByContinueTask) { + public DownloadRunnableInternal(DownloadInfoPanel downPanel, long urlTimestamp, boolean invokeByContinueTask, int failCnt) { this.downPanel = downPanel; this.urlTimestamp = urlTimestamp; this.invokeByContinueTask = invokeByContinueTask; + this.failCnt = failCnt; iNeedAV = downPanel.iNeedAV; downloader = iNeedAV.getDownloader(); urlQuery = downPanel.url;