java - How to access arrays from multi-thread? -
simply speaking, problem follows: i have class named test , has 3 double arrays,named array1, array2,array3 respectively(assuming have same length).it has major function named estep, , need implement function multi-threading improve speed. in estep, need modify array1 , array2, , array3 read .i define indicator variable named which_array indicator array modify.i passed 3 arrays estep , modify array1 , array2. my code follows , test , it works fine modification of array1 , array2 in estep can seen in test class . still have doubt if absolutely right. i'm wondering if should add volatile 3 array1 in test class or should need synchronization mechanism?. any advice appreciated! public class test{ double[] array1; double[] array2; double[] array3; //for simplifization, omitted code allocation , initialization of the arrays. public void estepintest() { final countdownlatch countdown = new countdownlatch(2); estep modifyarray1 = new est