I am working with threads as a fledgling. So I need some help.
For certain work I need a single array-list, which value will be shared by all threads. I want something like this, main() class will provide the array-list to the threads in time of thread creation. Threads will add values to the array-list and a change made by a thread will be reflected in every copy of that array-list and importantly this have to be done in a synchronized fashion.
For example, main() class has given two threads the array-list. Then first thread added a value on slot 1 of the array, second thread while adding will see the change and when it will add,it will add in the second position. When main will give the array list to a new thread all this changes done previously will be readily included, and it will start adding from the third or later positions. Another thing is, only one thread can make a change at a time or it should be synchronized.
How can I do this in java? Can any one help me?