diff --git a/common/src/main/java/ctbrec/recorder/download/hls/AbstractHlsDownload2.java b/common/src/main/java/ctbrec/recorder/download/hls/AbstractHlsDownload2.java index e9a858b5..e2938e59 100644 --- a/common/src/main/java/ctbrec/recorder/download/hls/AbstractHlsDownload2.java +++ b/common/src/main/java/ctbrec/recorder/download/hls/AbstractHlsDownload2.java @@ -23,6 +23,7 @@ import java.util.Locale; import java.util.Map; import java.util.Map.Entry; import java.util.Optional; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.stream.Collectors; @@ -151,7 +152,17 @@ public abstract class AbstractHlsDownload2 extends AbstractDownload { } protected void execute(SegmentDownload segmentDownload) { - downloadExecutor.submit(segmentDownload); + CompletableFuture.supplyAsync(() -> downloadExecutor.submit(segmentDownload), downloadExecutor) + .whenComplete((result, executor) -> { + try { + segmentDownloadFinished(result.get()); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + e.printStackTrace(); + } catch (ExecutionException e) { + e.printStackTrace(); + } + }); } private void handleHttpException(HttpException e) throws IOException { @@ -343,7 +354,6 @@ public abstract class AbstractHlsDownload2 extends AbstractDownload { OutputStream targetStream = getSegmentOutputStream(prefix, tmp.getName()); SegmentDownload segmentDownload = new SegmentDownload(model, playlist, segmentUrl, client, targetStream); execute(segmentDownload); - segmentDownloadFinished(segmentDownload); } } }