implement Main.java

This commit is contained in:
2026-06-08 00:39:47 +03:30
parent 09ac99ee80
commit 5fdcd9349c
+26
View File
@@ -37,12 +37,38 @@ public class Main {
// TODO: // TODO:
// Students may print helpful debug information here, // Students may print helpful debug information here,
// for example which chunk is assigned to which worker thread. // for example which chunk is assigned to which worker thread.
System.out.println(
"new thread " + workerThread.getName() + " created for chunk " + chunk.getChunkId()
);
} }
// 4. Create and start monitor thread // 4. Create and start monitor thread
ProgressMonitor monitor = new ProgressMonitor(config, chunks); ProgressMonitor monitor = new ProgressMonitor(config, chunks);
Thread monitorThread = new Thread(monitor, "Progress-Monitor"); Thread monitorThread = new Thread(monitor, "Progress-Monitor");
monitorThread.start();
for (Thread thread : workerThreads) {
thread.start();
}
try {
for (Thread thread : workerThreads) {
thread.join();
}
} catch (InterruptedException e) {
System.out.println("Download manager was interrupted. Stopping all workers...");
monitorThread.interrupt();
for (Thread worker : workerThreads) {
worker.interrupt();
}
Thread.currentThread().interrupt();
return;
}
// TODO: // TODO:
// Start the monitor thread before starting the workers // Start the monitor thread before starting the workers
// so that progress can be displayed while downloading happens. // so that progress can be displayed while downloading happens.