问题描述
在Citrix服务器上调试Eclipse RCP应用程序的启动缓慢时,我发现java.io.createTempFile(String,String,File)耗时5秒。它仅在第一次执行时执行此操作,仅对某些用户帐户执行此操作。具体来说,我注意到了Citrix匿名用户帐号。我没有尝试过许多其他类型的帐户,但是这种行为不会与管理员帐户一起展示。
While debugging slow startup of an Eclipse RCP app on a Citrix server, I came to find out that java.io.createTempFile(String,String,File) is taking 5 seconds. It does this only on the first execution and only for certain user accounts. Specifically, I am noticing it Citrix anonymous user accounts. I have not tried many other types of accounts, but this behavior is not exhibited with an administrator account.
此外,如果用户有权访问给定的目录是否。如果用户无法访问,则呼叫将需要5秒钟失败。如果他们有访问权限,则需要5秒钟的时间才能成功。
Also, it does not matter if the user has access to write to the given directory or not. If the user does not have access, the call will take 5 seconds to fail. If they do have access, the call with take 5 seconds to succeed.
这是在Windows 2003 Server上。我尝试过Sun的1.6.0_16和1.6.0_19 JRE,并看到相同的行为。
This is on a Windows 2003 Server. I've tried Sun's 1.6.0_16 and 1.6.0_19 JREs and see the same behavior.
我有点期待这是一个已知的问题,但没有什么都找不到似乎有人不得不在之前遇到过。
I googled a bit expecting this to be some sort of known issue, but didn't find anything. It seems like someone else would have had to have run into this before.
Eclipse Platform使用File.createTempFile()来测试各种目录,看看它们是否可以写入初始化和这个问题在我们的应用程序的启动时间增加了5秒。
The Eclipse Platform uses File.createTempFile() to test various directories to see if they are writeable during initialization and this issue adds 5 seconds to the startup time of our application.
我想像有人曾经遇到过这个问题,可能有一些洞察力。这是我执行的示例代码,以确定这个调用正在消耗时间。我还尝试了第二次调用createTempFile,并注意到后续调用几乎立即返回。
I imagine somebody has run into this before and might have some insight. Here is sample code I executed to see that it is indeed this call that is consuming the time. I also tried it with a second call to createTempFile and notice that subsequent calls return nearly instantaneously.
public static void main(final String[] args) throws IOException {
final File directory = new File(args[0]);
final long startTime = System.currentTimeMillis();
File file = null;
try {
file = File.createTempFile("prefix", "suffix", directory);
System.out.println(file.getAbsolutePath());
} finally {
System.out.println(System.currentTimeMillis() - startTime);
if (file != null) {
file.delete();
}
}
}
此程序的示例输出如下:
Sample output of this program is the following:
C:\>java.exe -jar filetest.jar C:/Temp
C:\Temp\prefix8098550723198856667suffix
5093
推荐答案
可能是导致问题的安全随机数生成器的初始化。特别是如果从操作系统不能获得安全的随机种子,则后退机制试图获得熵。 IIRC,其中一件事是列出临时文件,所以如果你有大量的那些不会帮助初创公司的表现。
It might be the intialisation of the secure random number generator which is causing the problem. In particular if a secure random seed is not obtainable from the operating system, then the fall-back mechanism attempts to gain entropy. IIRC, one of the things it does is to list temporary files, so if you have a large number of those that will not help start-up performance.
这篇关于为什么首先调用java.io.File.createTempFile(String,String,File)在Citrix上需要5秒钟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!