import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.io.*;
public class FileSorter extends Thread {
static int pli=16;
private static final int MAX_NUMBER = 10;
static double[] a1 = new double[8];
static double[] a2 = new double[8];
static double[][] array;
static int nThreads;
/**
* @param args
*/
public static void main(String[] args) throws IOException {
nThreads = Integer.parseInt(args[1]);
array = new double[nThreads][pli/nThreads];
System.out.println(nThreads);
Random random = new Random(System.currentTimeMillis());
PrintWriter out = new PrintWriter(new FileWriter("numbers.txt"));
for(int i = 0; i < pli; i++) {
out.println(random.nextInt(MAX_NUMBER));
out.flush();
}
readArray();
for (int i=0;i<nThreads;i++){
for (int j=0;j<pli/nThreads;j++){
System.out.println(array[i][j]);
}
System.out.println("");
}
System.out.println("");
SortingThread t[] = new SortingThread[nThreads];
for(int i=0; i<nThreads; i++){
t[i] = new SortingThread(array[i]);
t[i].setThreadId(i);
t[i].start();
}
for(int qq = 0;qq<nThreads;qq++){
if(t[qq]!=null){
try {
t[qq].join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
for (int i=0;i<nThreads;i++){
for (int j=0;j<pli/nThreads;j++){
System.out.println(array[i][j]);
}
System.out.println("");
}
System.out.println("");
MergingThread t2[] = new MergingThread[nThreads-1];
/* for(int j=0; j<nThreads-1; j++){
t2[j] = new MergingThread(array[0],array[1]);
t2[j].start();
i+=unsrtArray.length/2;
try {
t2[j].join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}*/
t2[0] = new MergingThread(array[0],array[1]);
t2[0].start();
t2[1] = new MergingThread(array[2],array[3]);
t2[1].start();
for(int qq = 0;qq<nThreads-2;qq++){
if(t2[qq]!=null){
try {
t2[qq].join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
// for(int i1=0; i1<16; i1++){
a1=t[0].getSortedArray().length[i];
a2=t[1].getSortedArray();
for (int j=0;j<8;j++){
System.out.println(a2);
}
System.out.println("");
// }
t2[2] = new MergingThread(a1,a2);
t2[2].start();
}
public static double[][] readArray() throws IOException{
Reader r = new BufferedReader(new FileReader("numbers.txt"));
StreamTokenizer stok = new StreamTokenizer(r);
stok.parseNumbers();
stok.nextToken();
int i=0;
int j=0;
while (stok.ttype != StreamTokenizer.TT_EOF) {
if (stok.ttype == StreamTokenizer.TT_NUMBER){
array[i][j] = stok.nval;
j++;
if(j==pli/nThreads){
i++;
j=0;
}
stok.nextToken();
}
}
return array;
}
}
can anybody help me?????? plz!!!!!!