Develop #1

Open
Fateme_Azizi wants to merge 6 commits from develop into main
Showing only changes of commit ef6a05b445 - Show all commits
+20 -14
View File
@@ -34,45 +34,51 @@ 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());
}
System.out.println();
// 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();
monitorThread.start();
// 5. Start worker threads
// TODO:
// Start each worker thread in workerThreads.
// Use a loop and call start() on each thread.
for(Thread thread : workerThreads) {
thread.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:
// This should be done inside a try-catch block for InterruptedException
for (Thread thread : workerThreads) {
try {
thread.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
// 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.
try {
monitorThread.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
// NOTE:
// this final report may show 0 progress because no worker has actually run yet.
// Until students complete the thread start/join TODOs above,