In a multithreaded environment I have a Singleton with a static ArrayList.
Let's say one thread gets the instance and is doing a "for" loop to the ArrayList. Just reading. No updates. This might take sometime to complete. While this happens, another thread updates the ArrayList.
What will happen to the loop (first thread)? Ideally I would like the "for" loop to complete with "old" data and if I get the instance again, then to get the new set of data.
Is the trick in this case to not use volatile ? Or create a new ArrayList from the static ArrayList for the "for" loop? Or... ?