From 10a49e83e5753044dcb5d7b67949cc9ce64fb7e3 Mon Sep 17 00:00:00 2001 From: Matin Date: Sat, 13 Jun 2026 20:28:01 +0430 Subject: [PATCH] finish --- src/java/Main.java | 23 +++++++++++++++++++---- src/java/ProgressMonitor.java | 2 +- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/java/Main.java b/src/java/Main.java index 82bd239..77b06e7 100644 --- a/src/java/Main.java +++ b/src/java/Main.java @@ -37,6 +37,7 @@ public class Main { // TODO: // Students may print helpful debug information here, // for example which chunk is assigned to which worker thread. + System.out.println("Assignment Chunk : " + chunk.chunk.getChunkId() + "(" + chunk.getChunkSizeMB) + "MB)" + workerThread.getName()) ; } // 4. Create and start monitor thread @@ -48,12 +49,17 @@ public class Main { // 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: @@ -61,9 +67,13 @@ public class Main { // This should be done inside a try-catch block for InterruptedException. // // Hint: - // for (Thread thread : workerThreads) { - // thread.join(); - // } + try { + for (Thread thread : workerThreads) { + thread.join(); + } + } catch (java.lang.Exception e) { + System.out.println("Main thread was interrupted while waiting for workers.") + } // TODO: // After all workers finish, the monitor thread may also need to stop. @@ -76,6 +86,11 @@ public class Main { // NOTE: // this final report may show 0 progress because no worker has actually run yet. // Until students complete the thread start/join TODOs above, + try { + monitorThread.join(); + } catch (InterruptedException e) { + System.out.println("Main thread was interrupted while waiting for monitor."); + } // 7. Print final report System.out.println(); diff --git a/src/java/ProgressMonitor.java b/src/java/ProgressMonitor.java index 1924bc1..5f1d5f9 100644 --- a/src/java/ProgressMonitor.java +++ b/src/java/ProgressMonitor.java @@ -60,7 +60,7 @@ public class ProgressMonitor implements Runnable { // If all chunks are completed, print a final message and exit the loop if (completedChunks == chunks.size()) { - + System.out.println("Progress Monitor: All chunks successfully downloaded. Exiting monitor thread."); break; }