Skip to main content

Parallel Word Counter

Challenge on lesson: Checkpoint: Concurrency

CHALLENGE
Difficulty: intermediate+25 XP

Build Solution: - static Map<String, Integer> countWords(List<String> chunks, int threads): - split the chunk list into threads sublists (like parallelSum) - each thread counts words in its chunks into its OWN local HashMap<String, Integer> - after joining all threads, MERGE the maps into one - return the merged map The merge must happen after every join โ€” before that, thread-local maps are confined and safe. threads <= 0 โ†’ empty map; empty chunks fine.

Back to lesson: Checkpoint: Concurrency