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.