Java 与Eclipse相比,可运行的Jar文件速度较慢

Java 与Eclipse相比,可运行的Jar文件速度较慢,java,eclipse,windows,oracle,Java,Eclipse,Windows,Oracle,我只发现了一小部分关于这个问题的威胁,但似乎没有什么能解决它 我的代码在Eclipse中运行不到10秒。如果我将这个项目提取到一个可运行的jar文件中,需要5-10分钟 我所做的:我读取两个.txt文件,将它们合并,排序,分离并保存它们。 这是我的代码: package de.***.timcooparser; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import ja

我只发现了一小部分关于这个问题的威胁,但似乎没有什么能解决它

我的代码在Eclipse中运行不到10秒。如果我将这个项目提取到一个可运行的jar文件中,需要5-10分钟

我所做的:我读取两个.txt文件,将它们合并,排序,分离并保存它们。 这是我的代码:

package de.***.timcooparser;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JOptionPane;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;

import com.google.code.externalsorting.ExternalSort;


public class TimCooParser {

  private static List<String> listCoordinates = new ArrayList<String>();
  private static List<String> listTimestamps = new ArrayList<String>();
  private static List<String> listTimeCoord = new ArrayList<String>();


  public static void main(String[ ] args) throws IOException {

    //Start Time
    long d1 = System.currentTimeMillis();

    //Create Path
      String path = new File("").getAbsolutePath();

    //Readfiles
    File fileTimeCoord = new File (path+"\\TimestampsCoordinates.txt");
    File fileTimeCoord2 = new File (path+"\\TimestampsCoordinates2.txt");
    File fileCoordinates = new File (path+"\\Coordinates.txt");
    File fileTimestamps = new File (path+"\\Timestamps.txt");

    try{


      if (fileTimeCoord.exists()){
        fileTimeCoord.delete();
      }
      fileCoordinates.createNewFile();

      //Read Coordinates an Timestamps and merge them
      InputStream is1 = new FileInputStream(fileTimestamps);
      InputStreamReader instrm1 = new InputStreamReader(is1);
      BufferedReader br1 = new BufferedReader(instrm1);

      InputStream is2 = new FileInputStream(fileCoordinates);
      InputStreamReader instrm2 = new InputStreamReader(is2);
      BufferedReader br2 = new BufferedReader(instrm2);

      String line = "", line2 = "";
      Integer i = 0;
      while ((line = br1.readLine()) != null){
        line2 = br2.readLine();
        String[] arrayTemp = line2.split(" ");
        listTimeCoord.add(line+","+arrayTemp[0] + "," + arrayTemp[1]);
        i++;

        if (i>=500){
          i=0;
          saveFiles(fileTimeCoord);
        }
      }
      br1.close();
      br2.close();

      //Sort File and delete old file
      ExternalSort.sort(fileTimeCoord, fileTimeCoord2);
      fileTimeCoord.delete();

      //Delete old files
      if (fileCoordinates.exists()){
        fileCoordinates.delete();
      }
      fileCoordinates.createNewFile();

      if (fileTimestamps.exists()){
        fileTimestamps.delete();
      }
      fileTimestamps.createNewFile();


      //Read TimeCoord and override Timestamps and Coordinates
      InputStream is3 = new FileInputStream(fileTimeCoord2);
      InputStreamReader instrm3 = new InputStreamReader(is3);
      BufferedReader br3 = new BufferedReader(instrm3);

      line = "";
      listCoordinates.clear();
      listTimestamps.clear();
      Integer ct = 0;
      while ((line = br3.readLine()) != null){
        String[] arrayTemp = line.split(",");
        listTimestamps.add(arrayTemp[0]);
        listCoordinates.add(arrayTemp[1] + " " + arrayTemp[2]);
        ct++;

        if (ct >= 500){
          saveFiles(fileTimestamps, fileCoordinates);
        }
      }
      br3.close();

      // Delete old Files
      fileTimeCoord2.delete();

      //get end Time
      long d2 = System.currentTimeMillis();

      //Get diff time
      long diff = d2 - d1;
      String diffTime = "Finished in " + ((diff / (60 * 60 * 1000)) % 24) + " hours " + ((diff / (60 * 1000)) % 60) + " minutes and "
          + ((diff / 1000) % 60) + " seconds";

      JOptionPane.showMessageDialog(null,  "Parser finished in: \n" + diffTime,"TimesCoord Parser", JOptionPane.INFORMATION_MESSAGE);
    }
    catch (FileNotFoundException e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(null,"Parser Error:\n" + e,"TimesCoord Parser", JOptionPane.CANCEL_OPTION);
    } 
    catch (IOException e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(null,"Parser Error:\n" + e,"TimesCoord Parser", JOptionPane.CANCEL_OPTION);
    }
  }

  private static void saveFiles(File fileTimestamps, File fileCoordinates) throws IOException {

    List<String> listCoordinates2 = new ArrayList<String>();
    List<String> listTimestamps2 = new ArrayList<String>();

    listCoordinates2.addAll(listCoordinates);
    listCoordinates.clear();

    listTimestamps2.addAll(listTimestamps);
    listTimestamps.clear();

    //Write to File
    BufferedWriter bw1 = new BufferedWriter(    new FileWriter(fileTimestamps, true));

    for (String string : listTimestamps2) {
      bw1.append(string + "\n");
    }
    bw1.close();

    //Write to File
    BufferedWriter bw2 = new BufferedWriter(    new FileWriter(fileCoordinates, true));

    for (String string : listCoordinates2) {
      bw2.append(string + "\n");
    }
    bw2.close();


  }

  private static void saveFiles(File fileTimeCoord) throws IOException {

    List<String> listTimeCoord2 = new ArrayList<String>();

    listTimeCoord2.addAll(listTimeCoord);
    listTimeCoord.clear();

    //Write to File
    BufferedWriter bw1 = new BufferedWriter(    new FileWriter(fileTimeCoord, true));

    for (String string : listTimeCoord2) {
      bw1.append(string + "\n");
    }
    bw1.close();        
  }



  public static String TimestampToDate(long stringDate)
  {
    DateTimeZone zone = DateTimeZone.forID("Europe/Berlin");
    DateTimeZone.setDefault(zone);
    DateTime actual = new DateTime(stringDate);
    String dateString = actual.toString("yyyy-MM-dd'T'HH:mm:ssZZ");
    return dateString;

  }
}
这是我的eclipse.ini:

-启动
plugins/org.eclipse.equinox.launcher_1.3.0.v20140415-2008.jar
--启动程序库
plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.200.v20140603-1326
-产品
org.eclipse.epp.package.java.product
--launcher.defaultAction
开放文件
--launcher.XXMaxPermSize
256M
-炫耀
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
开放文件
--launcher.appendVmargs
-vmargs
-Dosgi.requiredJavaVersion=1.6
-Xms512m
-Xmx1024m
我能做些什么来解决这个问题


PS:它独立于“externalsortinginjava..”库。

请尝试确保在启动应用程序时使用与Eclipse相同的内存选项


看起来命令行参数应该是
-Xms512m-Xmx1024m

我已经找到了需要很多时间的行

if (ct >= 500){
   saveFiles(fileTimestamps, fileCoordinates);
}
我把这个改成了

   if (ct >= 1000000000){
      saveFiles(fileTimestamps, fileCoordinates);
      ct=0;
   }
}
br3.close();
saveFiles(fileTimestamps, fileCoordinates);
上述变化也是一样的(i>500的代码)

现在它以1秒的时间接收Eclipse,以jar文件的形式接收3秒


但是为什么Eclipse中的代码比jar文件更快,这个问题还没有解决

使用此命令,解析时间超过9分钟。没有超过12分钟。在Eclipse中只需12秒。。。