Develop #1
+19
-4
@@ -37,6 +37,7 @@ 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("Assignment Chunk : " + chunk.chunk.getChunkId() + "(" + chunk.getChunkSizeMB) + "MB)" + workerThread.getName()) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. Create and start monitor thread
|
// 4. Create and start monitor thread
|
||||||
@@ -48,12 +49,17 @@ public class Main {
|
|||||||
// so that progress can be displayed while downloading happens.
|
// so that progress can be displayed while downloading happens.
|
||||||
//
|
//
|
||||||
// Example idea:
|
// Example idea:
|
||||||
// monitorThread.start();
|
monitorThread.start();
|
||||||
|
|
||||||
|
|
||||||
// 5. Start worker threads
|
// 5. Start worker threads
|
||||||
// TODO:
|
// TODO:
|
||||||
// Start each worker thread in workerThreads.
|
// Start each worker thread in workerThreads.
|
||||||
// Use a loop and call start() on each thread.
|
// Use a loop and call start() on each thread.
|
||||||
|
for(Thread thread : workerThreads)
|
||||||
|
{
|
||||||
|
thread.start() ;
|
||||||
|
}
|
||||||
|
|
||||||
// 6. Wait for workers to finish
|
// 6. Wait for workers to finish
|
||||||
// TODO:
|
// TODO:
|
||||||
@@ -61,9 +67,13 @@ public class Main {
|
|||||||
// This should be done inside a try-catch block for InterruptedException.
|
// This should be done inside a try-catch block for InterruptedException.
|
||||||
//
|
//
|
||||||
// Hint:
|
// Hint:
|
||||||
// for (Thread thread : workerThreads) {
|
try {
|
||||||
// thread.join();
|
for (Thread thread : workerThreads) {
|
||||||
// }
|
thread.join();
|
||||||
|
}
|
||||||
|
} catch (java.lang.Exception e) {
|
||||||
|
System.out.println("Main thread was interrupted while waiting for workers.")
|
||||||
|
}
|
||||||
|
|
||||||
// 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.
|
||||||
@@ -76,6 +86,11 @@ public class Main {
|
|||||||
// NOTE:
|
// NOTE:
|
||||||
// this final report may show 0 progress because no worker has actually run yet.
|
// this final report may show 0 progress because no worker has actually run yet.
|
||||||
// Until students complete the thread start/join TODOs above,
|
// 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
|
// 7. Print final report
|
||||||
System.out.println();
|
System.out.println();
|
||||||
|
|||||||
Reference in New Issue
Block a user