Steven Rodeo wrote:
this won't stop other threads from changing the contents of the array ?. The example I gave you, shows a thread (sleeping for 8 seconds) holding the lock. And another thread modifying the contents of the Array.
So I wanted to know, how I can make it thread safe ( the whole Array ), not just the reference
One requirement of thread safety is cooperation. All the threads must behave together to achieve thread safety. This means that all the threads must agree on how they will behave with the data -- or better yet, the data should be held private, with all public methods that access the data to behave in a cooperative manner.
If you need to operate on the whole array -- and for an operation that is longer than a single read or write -- you can't just give away access to data and expect it to be thread safe.
Henry