forked from j62/ctbrec
Fix race condition in HlsDownload
This commit is contained in:
parent
32429b192c
commit
1c8758ef52
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue