0

I need to split an array into 5 parts (the last one would not be an equal part probably),and feed into threads for processing in parallel. An attempt is as below:

int skip=arr.length/5;
        for(int i=0;i<arr.length;i+=skip){
                int[] ssub;
                if(i+skip>=arr.length){
                    sub=new int[arr.length-1]
                }
                else
                {
                    sub=new int[skip+1];
                }
                System.arraycopy(arr,0,sub,0,sub.length);
                Thread t=new Runnable(barrier,sub){

                };
                t.start();
        }

Any suggestion to make it more functional and avoiding local arrays is welcome.

IUnknown
  • 9,301
  • 15
  • 50
  • 76

1 Answers1

1

Well in terms of making well organized Threads. You should look into ExecutorService, Simple youtube video on ExecutorService

In terms of organizing the arrays you can either split them non-locally or can create a Queue for that look towards, Java Queue implementations, which one?

These threads may work at different speeds so a Queue is recommended please look into them.

Community
  • 1
  • 1
Ya Wang
  • 1,758
  • 1
  • 19
  • 41