I have this code
List<Object> myList = new ArrayList<>();
public void RunOperation(){
myThread = new Thread() {
@Override
public void run() {
for (int i = 0; i < ReallyHighNumber; i++) {
myList.add(SimulationStep(i));
}
}
};
myThread.start();
}
public List<Object> GetData(){
return myList;
}
I want to return partial values while the thread executes, since the number of reps may get too large. One of the workarounds was to run the operation 100 times after each GetData (), but it is not appropriate.
I tried to use a volatile and atomic variable, but I do not know if it was a wrong use, but it continued to give competition problem when calling GetData ().
The synchronized method with wait () and notify () did not resolve either, as it expects the thread to terminate the loop.
Does anyone know which method or path to use to resolve this problem?
Thanks for the help!