This commit is contained in:
2026-07-19 06:12:05 +03:30
parent 9e5c715088
commit 1b7327b9d9
5 changed files with 239 additions and 66 deletions
+25 -34
View File
@@ -34,50 +34,41 @@ public class Main {
workerThreads.add(workerThread);
// TODO:
// Students may print helpful debug information here,
// for example which chunk is assigned to which worker thread.
System.out.println("Assigned Chunk #" + chunk.getChunkId()
+ " (" + chunk.getChunkSizeMB() + " MB) to " + workerThread.getName());
}
// 4. Create and start monitor thread
ProgressMonitor monitor = new ProgressMonitor(config, chunks);
Thread monitorThread = new Thread(monitor, "Progress-Monitor");
// TODO:
// Start the monitor thread before starting the workers
// so that progress can be displayed while downloading happens.
//
// Example idea:
// monitorThread.start();
// 5. Start worker threads
// TODO:
// Start each worker thread in workerThreads.
// Use a loop and call start() on each thread.
monitorThread.start();
// 6. Wait for workers to finish
// TODO:
// Wait for all worker threads to complete by calling join().
// This should be done inside a try-catch block for InterruptedException.
//
// Hint:
// for (Thread thread : workerThreads) {
// thread.join();
// }
// TODO:
// After all workers finish, the monitor thread may also need to stop.
// Depending on how ProgressMonitor is implemented, students may:
// - wait for it to finish on its own, or
// - add a stopping mechanism in ProgressMonitor later.
//
// If your monitor finishes automatically, you may join it here.
for (Thread thread : workerThreads) {
thread.start();
}
for (Thread thread : workerThreads) {
try {
thread.join();
} catch (InterruptedException e) {
System.out.println("Main thread interrupted while waiting for " + thread.getName());
Thread.currentThread().interrupt();
}
}
try {
monitorThread.join();
} catch (InterruptedException e) {
System.out.println("Main thread interrupted while waiting for monitor.");
Thread.currentThread().interrupt();
}
// NOTE:
// this final report may show 0 progress because no worker has actually run yet.
// Until students complete the thread start/join TODOs above,
// 7. Print final report
System.out.println();
System.out.println("=== Final Report ===");