I have a list in which items are iterated and processed. These should be added to another list after being processed. This is legacy code and I have to implement parallel processing.
class demo{
public void function1(){
List<TestPojo> newList = new ArrayList<>();
oldList.parallelStream.forEach(item->
function2(newList,item)
);
}
public void function2(List<TestPojo> newList, Item item){
TestPojo testPojo = formPojo(item);
synchronized(newList){
newList.add(testPojo);
}
}
}
Owing to certain legacy conditions, I cannot change the function signatures. Will this cause an issue? Am I breaking any rules by not using a synchronized list?