implementing main.java

This commit is contained in:
2026-07-17 12:29:31 +03:30
parent a3d55ca32a
commit 40d53cbb66
+20 -22
View File
@@ -34,36 +34,34 @@ 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());
}
// 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();
try {
for (Thread thread : workerThreads) {
thread.join();
}
} catch (InterruptedException e) {
System.out.println("Interrupted.");
return;
}
try {
monitorThread.join();
} catch (InterruptedException e) {
System.out.println("Interrupted.");
return;
}
// 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.