Java程序问题:先产生1万个随机数,再使用多线程对该数进行三种排序,分别记录排序运行时间,本人是新手,多谢列位指教了!

解决方案 »

  1.   

    public Class TestSortingPerformance {
       public static void main(String[] args) {
           new Thread() {
              public void run() {
                  sort1();
              }
           }.start();
           new Thread() {
              public void run() {
                  sort2();
              }
           }.start();
           new Thread() {
              public void run() {
                  sort3();
              }
           }.start();
       }
       
       static void sort1() {
           long t1 = System.currentTimeMillis();
           //Do sort
           /**implement sorting*/
           long segment = System.currentTimeMillis() - t1;
           System.out.print("Sort Method 1 cost :" + segment + " milseonds.");
       }
    }
      

  2.   

    其它sort2,sort3,注释什么应该不需要了,
    如果线程要调度或者排序方法的增加之类的实现另行设计了,呵呵
      

  3.   

    晕,忘了一点,
    public static void main(String[] args)   { 
      //生成随机数
      final int[] nums = genRandomInt(10000);然后
    new Thread(){ 
        public   void   run()   { 
            sortInt1(nums); 
        } 
    }.start(); 当然
    static void sort1(){ 变成 static void sortInt1(int[] rand)