This commit is contained in:
2026-06-12 00:21:31 +03:30
parent 9e5c715088
commit 28a223b02c
5 changed files with 59 additions and 8 deletions
+20
View File
@@ -23,8 +23,11 @@ public class DownloadWorker implements Runnable {
public void run() {
// TODO: Record the chunk start time in chunkStatus.
double downloaded = 0.0;
chunkStatus.setStartTimeMs(System.currentTimeMillis());
chunkStatus.setDownloadedMB(downloaded);
// TODO: Print a message that this chunk has started downloading.
System.out.println("Chunk #" + chunkStatus.getChunkId() + " started downloading.");
while (downloaded < chunkStatus.getChunkSizeMB()) {
// TODO: Generate a random sleep delay between min and max delay.
@@ -33,11 +36,28 @@ public class DownloadWorker implements Runnable {
// TODO: Increase downloaded, but do not go beyond chunk size.
// TODO: Save the updated downloaded value into chunkStatus.
// TODO: Optionally print step-by-step progress.
int delay = config.getMinStepDelayMs() + random.nextInt(config.getMaxStepDelayMs() - config.getMinStepDelayMs());
try {
Thread.sleep(delay);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
downloaded+=0.5;
if (downloaded > chunkStatus.getChunkSizeMB())
downloaded = chunkStatus.getChunkSizeMB();
chunkStatus.setDownloadedMB(downloaded);
}
// TODO: Mark the chunk as completed.
// TODO: Record the chunk end time in chunkStatus.
// TODO: Print a message that this chunk has finished downloading.
chunkStatus.setEndTimeMs(System.currentTimeMillis());
chunkStatus.setCompleted(true);
System.out.println("Chunk #" + chunkStatus.getChunkId() + " finished downloading.");
}
}