I have a Java program that reads in a large list of strings from a file, creating lists of them for every several hundred, and passes each list to a new thread that processes them in some manner. This may include modifying the list. I want to know the best approach to accomplishing this so that the threads don’t stomp on each other’s lists. Note that I do not care about what kind of data structure this list actually is. It could be an array, a List, a queue, stack, etc. and order does not matter.
Thanks,
Jared
If each thread has its own list, array, queue etc, there is no problem. If you use List.subList(), you must take a copy as this creates a view into the original list (which would cause a problem if you modified it in multiple threads).