A question about array sorting with multiple threads...
Hi,
i am trying to sort an integer containing array with multiple threads.
Problem is:
When i use one thread to sort an array of 5000000 integers, it takes around 1700 ms.
When i used two threads and give each of them an array of 2500000 integers, it takes around 1700 ms. again.
i tryed several times and same results everytime. I'm using a normal pc with one cpu.
is this logical?
thnx.
publicclass Test{
/**
* @param args
*/
staticint SIZE = 2500000;
staticint MAX = 1000000;
staticint MIN = 1;
publicstaticvoid main(String[] args)throws InterruptedException{
int[] a1 =newint[SIZE];
int[] a2 =newint[SIZE];
Random rnd =new Random();
//System.out.print("Array1:");
for(int i=0;i<SIZE ; i++){
//Returns a uniformly distributed int value between MIN (inclusive) and the specified value (exclusive)
a1[i] = rnd.nextInt(MAX-MIN+1) + MIN;
a2[i] = rnd.nextInt(MAX-MIN+1) + MIN;
//print genereated random numbers
//System.out.print(a1[i] + " ");
}
long x1 = System.currentTimeMillis();
SorterThread t1 =new SorterThread("1.",a1);
SorterThread t2 =new SorterThread("2.",a2);
t1.start();
t2.start();
t1.join();
t2.join();
long x2 = System.currentTimeMillis();
System.out.println();
System.out.println("elapsed time:" + (x2-x1));
}
}
>

