/** * Class to implement an example of concurrent computation. * The example computes a value from a large array. The concurrent * computation divides the array up among the threads, computes a partial * result on each thread. * * addem inherits from the Thread class * * @author (David John) * @version (November, 2009) */ public class addem extends Thread { // instance variables // the shared array, initialized by generatearray() private static double[] values; // instance variables to guide each thread of the computation private double partialsum; private int start; private int end; /** * Constructor for objects of class addem * * The parameters st and en initialize the instance variables * start and end. They are used as the index markers for * the thread computation. * */ public addem(int st, int en) { // initialise instance variables start = st; end = en; partialsum = 0.0; } /** * This method creates and initializes the shared array */ public static void generatearray(int size) { values = new double[size]; for(int i=0;i