There is a Java program that reads a list of orders and for each order starts a thread that receives data from SQL and prints the list of items in a given order to an order_name.html. I want to write a class that would generate all_orders.html that contains a list of items and the quantity of each item in all orders.
This is pretty straightforward in a single threaded environment. Write relevant data to order_name.csv, once all threads stop - parse these files and if the item exists - increment counter, else - add it to the list and set counter to 1. Once all files are parsed - create the report.
How can I do this in a multithreaded case? First, is it safe to create a
private static list<items(String name, int count)> and search/modify it from multiple threads? How to check that all threads finished, the
list<items> is complete and I can start preparing all_items.html? Is there a better method than a static list?
Edit: The program is multithreaded for historical reasons and to speed up processing multiple orders. The all_orders.html will be prepared using a single thread. What is the correct way to pass information to this thread. Specifically that order "a" has 2 items "foo" and 5 items "bar". And at the end that this order is fully processed and it has no additional items.