Help me figure out how to parallelize loops ..
Now let's say I have some method that should be called with different input parameters in the loop. The result is written to the array.
Each loop iteration is independent of the others. How to parallelize this process?
And how can I be in this situation:
public class MainClass(){ public void main(){ Generator g = new Generator(); for (int i = 0; i < 10; i++){ ArrayList<String> res = g.funcion(i); // здесь все должно выполняться последовательно System.put.println(res.size()); } } } public class Generator(){ public function(int i){ // Вот тут то и хотелось бы распараллелить выполнение метода function2 ArrayList<String> res = new ArrayList<String>(); res.addAll(function2(i)); res.addAll(function2(i*i)); } public function2(int i){ // ... } }
main
should be executed sequentially. Which of these is true? - VladD