finish
This commit is contained in:
+19
-4
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user