2
public double[] call() throws Exception {                                                                                                                         
    int [] zero = {0,0};
    double [] return_to_thread = { };
    List<Integer> MyList = new ArrayList<Integer>();
    for(int i = 0; i < N_W; i++) {
        if(MyList.size() == n) {
            N++;
        }
        MyList.clear();     
         int [] initial_point = {x,y};      
        for(int istep = 0; istep < n; istep++) {    
                randomWalk(initial_point);
                if(!MyList.contains(computeHashCode(initial_point)) && !MyList.contains(computeHashCode(zero))) {
                MyList.add(computeHashCode(initial_point));
                } else {
                    break;
                }
        }
        if(MyList.size() == n) {
        end_to_end_dis_sq += Math.pow(initial_point[0], 2) + Math.pow(initial_point[1], 2);
        }
    }

    return_to_thread[0] += N;
    return_to_thread[1] += S;
   // System.out.print(return_to_thread);
    Thread.sleep(3000);

    return return_to_thread;
}

The code above is the call() function that will return an array with double as the type.

public static void main(String [] args)  {
    ExecutorService service = Executors.newFixedThreadPool(1); 
    List<Future<double[]>> list = new ArrayList<Future<double[]>>();
    Callable<double[]> callable = new Callable_class_1a();
    for(int i = 0; i < 1; i++) {
        //Submit the task for execution.
        Future<double[]> future = service.submit(callable);
        list.add(future);
    }
    for(Future<double[]> futu : list) {
        try {
            System.out.print(Arrays.toString(futu.get()));
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        } finally {
    service.shutdown();
        }
}
}

And the code above is the main function that supposed to print out the value that I get from call() function. I ran this on Eclipse, and when I clicked run nothing happened.

I wonder what happened, and how do I solve this? I can clarify any part that confused you. This is my first every question on Stackoverflow, hope everyone treat me nicely :)

xxColderxx
  • 53
  • 6
  • There are a bunch of things missing to recreate this; can you add the definitions for: `x, y, n, N, N_W, S, end_to_end_dis_sq, randomWalk(), computeHashCode()`? When I tried with everything set to 0, I needed to initialize `return_to_thread = new double[2]`, and it did print the array. – boot-and-bonnet Oct 10 '19 at 21:20
  • Sorry currently not able to provide the definition codes right now. But what does the out come looks like when the array is printed? – xxColderxx Oct 12 '19 at 00:18
  • I just used 0 for the missing values, and had empty missing functions, so the result was `[0.0, 0.0]` – boot-and-bonnet Oct 12 '19 at 07:23

0 Answers0