加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

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

发布时间:2020-12-14 16:41:03 所属栏目:Java 来源:网络整理
导读:我们有一个应用程序通过分割数据并对其进行排序来导入大量的文件.运行JUnit测试用例时,整个过程大约需要16分钟. 同样的测试,用mvn清洁测试完成-Dtest = MyTest在34分钟内运行. 我们正在调用/ bin / sort来对文件进行排序.这种做法似乎花费更长时间.我不明白
我们有一个应用程序通过分割数据并对其进行排序来导入大量的文件.运行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中进行排序,这解释了性能损失.希望这个答案可以帮助别人.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读