Why does first call to java.io.File.createTempFile(String,String,File) take 5 seconds on Citrix?

Posted by Ben Roling on Stack Overflow See other posts from Stack Overflow or by Ben Roling
Published on 2010-04-09T15:39:31Z Indexed on 2010/04/09 15:43 UTC
Read the original article Hit count: 277

Filed under:
|
|
|

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.

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.

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.

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.

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

© Stack Overflow or respective owner

Related posts about java

Related posts about eclipse