I have the following problem, and I am not sure how to design parts of the solution:
I have a large text file that I read line by line. I need to process each line and update a HashMap.
AFAIK I need one producer thread to read the lines from the file, and dispatch the lines to a pool of consumer threads. The consumer threads should update the ConcurrentHashMap and then get new lines.
My questions are: How can the consumer threads access the ConcurrentHashMap? If I use a fixed thread pool, does the producer need to add the line to a queue first, or can it simply submit or execute a new consumer?
EDIT: Zim-Zam is correct; I want the consumers to dump their results into the ConcurrentHashMap when they finish.
I create the ConcurrentHashMap in the main thread, and pass references to it to the Consumers in their constructors. The Consumers should either add or increment an AtomicInteger in their run methods. How can I tell in the main thread when all of the lines are read and the consumers are finished?
Thanks again.