Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package multithreadedmergesort;
- import java.io.*;
- /**
- *
- * @author Davidthefat
- */
- public class MergeSort
- {
- private static String[][] array;
- private static String[] filename;
- private static Thread[] thr;
- public static void main(String[] args)
- {
- filename = new String[args.length];
- array = new String[args.length][];
- for(int i = 0; i < args.length; i++)
- {
- filename[i] = args[i];
- array[i] = new String[Integer.parseInt(filename[i].substring(0, filename[i].indexOf(".")))];
- System.out.println(filename[i] + " " + array[i].length);
- }
- thr = new Thread[args.length];
- try
- {
- for(int i = 0; i < thr.length; i++)
- {
- thr[i] = new ReadThread(array[i], filename[i]); //Reads in the files
- thr[i].start();
- thr[i].join();
- }
- for(int i = 0; i < thr.length; i ++)
- {
- thr[i] = new Sort(array[i]);
- thr[i].start();
- }
- for(int i = 0; i < thr.length; i ++)
- {
- thr[i].join();
- System.out.println(filename[i] + " Done");
- }
- }
- catch(InterruptedException e)
- {
- System.out.println(e.getMessage());
- }
- try
- {
- BufferedWriter out;
- for(int i = 0; i < array.length; i ++)
- {
- System.out.println("Printing : " + filename[i]);
- out = new BufferedWriter(new FileWriter(array[i].length + "output.txt"));
- for(int k = 0; k < array[i].length; k ++)
- {
- out.write(array[i][k]);
- out.newLine();
- }
- out.close();
- }
- }
- catch (IOException e)
- {
- System.out.println(e.getMessage());
- }
- System.out.println("Done");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement