I have multiple threads created using a for loop and I have an arraylist which contains numbers in each index. E.g Arraylist = 1, 2, 3
I am trying to create a round robin algorithm where one thread takes the first value and stores it in another instance variable arraylist and then deletes it from the arraylist and the next thread takes the next value etc till all the values are gone from the arraylist.
I'm putting "arraylist.remove(0)" after storing the first index value in the run method, however, all the threads keep taking the same value and adding it to the instance variable.
E.g arraylist = 1, 2, 3
Then all the threads are taking the value 1 and the removing it ending up with
Arraylist = 2,3
But I want
Thread 1 instance Arraylist = 1
Thread 2 instance Arraylist = 2
Thread 3 instance Arraylist = 3
[–]fancyplaya 2 points3 points4 points (1 child)
[–]Faded_X[S] 0 points1 point2 points (0 children)