Concurrent ArrayList read/write
I have a situation where one thread puts data in an ArrayList and another thread reads that data. I am not really concerned whether the thread that reads the data can instantly tell that the data is there, but rather if there is a chance the reader thread might not ever see the data at all. Here is an example:
In this scenario if for some reason the writer thread is taking a while to add something to the list, is it possible the reader thread might do something like cache the entire list and pretty much never see when a new element is added so it just keeps sleeping? And if it is possible is there a way to prevent it without synchronizing access to the entire structure, because I really don't need to. I have been running my program like this for quite some time and haven't run into any issues, but this potential problem lingers in the back of my mind.
In this scenario if for some reason the writer thread is taking a while to add something to the list, is it possible the reader thread might do something like cache the entire list and pretty much never see when a new element is added so it just keeps sleeping? And if it is possible is there a way to prevent it without synchronizing access to the entire structure, because I really don't need to. I have been running my program like this for quite some time and haven't run into any issues, but this potential problem lingers in the back of my mind.