微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java – 为什么我的应用程序在IntelliJ中比命令行运行得更快?

我们有一个应用程序通过分割数据并对其进行排序来导入大量的文件.运行JUnit测试用例时,整个过程大约需要16分钟.

同样的测试,用mvn清洁测试完成-Dtest = MyTest在34分钟内运行.

我们正在调用/ bin / sort来对文件进行排序.这种做法似乎花费更长时间.我不明白有什么不同

看看IntelliJ它运行

/Library/Java/JavaVirtualMachines/1.6.0_26-b03-383.jdk/Contents/Home/bin/java -Didea.launcher.port=7532 -Didea.launcher.bin.path=/Applications/IntelliJ IDEA 10.app/bin -Dfile.encoding=UTF-8 -classpath %classhpath% com.intellij.rt.execution.application.AppMain com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit4 xxx.IntTestImportProcess,testImportProcess

我在OS X上.所有的类都使用Spring注入.什么是一些可能的建议是在IntelliJ的绩效收益背后的理论?测试是一样的.我不能分享所有的代码,因为有这么多.但是如果需要,我可以添加任何细节.

这是我的主要课程,我是如何运行的.

public static void main(String... args) throws IOException {
        if(args.length != 2) {
            System.out.println("Usage: \n  java -jar client.jar spring.xml data_file");
            System.exit(1);
        }
        ApplicationContext applicationContext = new FileSystemXmlApplicationContext(args[0]);
        PeriodFormatter formatter = new PeriodFormatterBuilder()
                .appendMinutes()
                .appendSuffix("minute","minutes")
                .appendSeparator(" and ")
                .appendSeconds()
                .appendSuffix("second","seconds")
                .toFormatter();
        URI output = (URI) applicationContext.getBean("workingDirectory");
        File dir = new File(output);
        if(dir.exists()) {
            Files.deleteDirectoryContents(dir.getCanonicalFile());
        }
        else {
            dir.mkdirs();
        }
        ImportProcess importProcess = applicationContext.getBean(ImportProcess.class);
        long start = System.currentTimeMillis();
        File file = new File(args[1]);
        importProcess.beginImport(file);
        Period period = new Period(System.currentTimeMillis() - start); // in milliseconds
        System.out.println(formatter.print(period.toPeriod()));
    }

我决定删除JUnit,只需使用一个main()方法.结果完全一样. IntelliJ再次.这是疯狂的日志.

使用IntelliJ

DEBUG [ main] 2011-08-18 13:05:16,259 [er.DelimitedTextUnixDataSorter] Sorting file [/Users/amirraminfar/Desktop/import-process/usage]
DEBUG [ main] 2011-08-18 13:06:09,546 [er.DelimitedTextUnixDataSorter] Sorting file [/Users/amirraminfar/Desktop/import-process/customer]

用java -jar

DEBUG [ main] 2011-08-18 12:10:16,726 [er.DelimitedTextUnixDataSorter] Sorting file [/Users/amirraminfar/Desktop/import-process/usage]
DEBUG [ main] 2011-08-18 12:15:55,893 [er.DelimitedTextUnixDataSorter] Sorting file [/Users/amirraminfar/Desktop/import-process/customer]

排序命令是

sort -t'    ' -f -k32,32f -k18,18f -k1,1n

如上所述,Intellij中的排序需要1分钟,但在java -jar中需要5分钟!

更新

我使用/Library/Java/JavaVirtualMachines/1.6.0_26-b03-383.jdk/Contents/Home/bin/java运行所有内容,排序仍然需要5分钟以上.

解决方法

谢谢大家帮忙.事实证明IntelliJ开始使用LANG = C进行排序.认情况下,Mac OS X终端在UTF8中进行排序,这解释了性能损失.希望这个答案可以帮助别人.

原文地址:https://www.jb51.cc/java/124616.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐