implementing main.java
This commit is contained in:
+20
-22
@@ -34,36 +34,34 @@ public class Main {
|
|||||||
|
|
||||||
workerThreads.add(workerThread);
|
workerThreads.add(workerThread);
|
||||||
|
|
||||||
// TODO:
|
System.out.println("Assigned Chunk " + chunk.getChunkId());
|
||||||
// Students may print helpful debug information here,
|
|
||||||
// for example which chunk is assigned to which worker thread.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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();
|
||||||
// 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
|
// 5. Start worker threads
|
||||||
// TODO:
|
for (Thread thread : workerThreads)
|
||||||
// Start each worker thread in workerThreads.
|
thread.start();
|
||||||
// Use a loop and call start() on each thread.
|
|
||||||
|
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:
|
// TODO:
|
||||||
// After all workers finish, the monitor thread may also need to stop.
|
// After all workers finish, the monitor thread may also need to stop.
|
||||||
|
|||||||
Reference in New Issue
Block a user