简体   繁体   English

创建临时文件非常慢

[英]Creating a temp file is incredibly slow

Any reason why a call to 致电的任何理由

File.createTempFile("prefix", ".suffix", new File("C:\\");

might take 40-50 seconds to complete? 可能需要40-50秒才能完成?

Update: I knocked up a little test harness that benchmarks creating 100 test files on C:\\ and the default tmp folder. 更新:我敲了一些测试工具,以测试在C:\\和默认tmp文件夹上创建100个测试文件为基准。 Specifying "C:\\" is consistently ~0.9ms slower than just leaving it on the default, allowing for JVM warmup time, GC pauses etc. (No clue why this should be, but its not a problem.) 与仅将其保留为默认值相比,指定“ C:\\”始终要慢0.9ms,从而允许JVM预热时间,GC暂停等。(不知道为什么会这样,但这不是问题。)

Not a single run suffered from anything like that level of delay, which suggests the app is doing something else first which is causing the problem. 一次运行都不会遇到类似延迟的情况,这表明该应用程序首先执行了其他操作,从而导致了问题。

Using Suns JVM 1.6.0_12 client. 使用Suns JVM 1.6.0_12客户端。

Time ago when developing a swing based application I came across a bug in the JVM which will cause the file requester open to be really slow if there is a big zip file on your desktop. 前段时间,在开发基于Swing的应用程序时,我遇到了JVM中的一个错误,如果您的桌面上有一个大的zip文件,它将导致文件请求器的打开速度非常慢。 And there is also another issue related when a big number of files exists in a folder. 当文件夹中存在大量文件时,还存在另一个相关问题。

Probably there can be a correlation with your issue. 可能与您的问题有关。 Which version of JDK are you usign ? 您使用哪个版本的JDK?

Please take a look at this thread for some info: 请查看此线程以获取一些信息:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4638397 http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4638397

http://groups.google.com/group/comp.lang.java.help/browse_thread/thread/ec8854f82f381123 http://groups.google.com/group/comp.lang.java.help/browse_thread/thread/ec8854f82f381123

Defrag the disk is also a good idea. 对磁盘进行碎片整理也是一个好主意。

try it: 试试吧:

try {
        // Create temp file.
        File temp = File.createTempFile("pattern", ".suffix");

        // Delete temp file when program exits.
        temp.deleteOnExit();

        // Write to temp file
        BufferedWriter out = new BufferedWriter(new FileWriter(temp));
        out.write("aString");
        out.close();
    } catch (IOException e) {
    }

I've seen file deletions on Windows take as long as a minute, but not file creation. 我已经看到Windows上的文件删除需要花费一分钟的时间,但是文件创建却没有。 I'd check to make sure you've defragged recently, and also that you have a reasonable number of files in your home. 我会检查一下,以确保您最近进行了碎片整理,并且您家中的文件数量也足够合理 Once you get past 1,000 files (including hidden ones) Windows has a real hard time. 一旦获得了超过1,000个文件(包括隐藏文件),Windows就会非常困难。

What happens if you don't specify c:\\ and allow Java to place the file in it's default location? 如果不指定c:\\并允许Java将文件放置在默认位置,会发生什么?

Virus checkers can sometimes make filesystem access slow, particularly on Windows systems. 病毒检查程序有时会使文件系统访问变慢,尤其是在Windows系统上。 They intercept all access to the filesystem and can do significant processing before allowing applications to write or read from the disk. 它们会拦截对文件系统的所有访问,并且可以在允许应用程序从磁盘写入或读取之前进行大量处理。

I'd check for and disable any virus checking software and see if that helps. 我会检查并禁用任何病毒检查软件,看看是否有帮助。

如果其他建议没有帮助(禁用病毒扫描程序并检查间谍软件),则建议您获取JDK源代码并运行IDE的调试器,以查看在createTempFile()期间它“挂在哪里”。

FWIW,我最终不得不运行磁盘清理

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM