~/ learn/ comp-348/ cards/ Getting a result back out
1 of 5

Start everything, then join

Start everything, then join

Answer

List<Thread> threads = new ArrayList<>(); for (String host : args) { Resolver task = new Resolver(host); Thread t = new Thread(task); t.start(); threads.add(t); } for (Thread t : threads) t.join(); // every result is now written and visible

The two loops are the whole idiom: the first overlaps every wait, the second collects. Fusing them into one loop (start then immediately join) would serialise the program while looking concurrent.

Harold 4e ch3 §Returning Information from a Thread

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/8155d63e-81a0-4a4d-95a2-1196eac5bd2a/flashcard utf-8 LF