I’m using Java 6.
Is it possible that two threads calling createTempFile (of the class java.io.File) get the same temp file?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Best way to get your answer is to look at the source code. At first there isn’t any synchronization in createTempFile, but to generate the temp file name, it is using SecureRandom which is ThreadSafe.
Then unless you are really unlucky, your file will always get a different name.
On top of that, createTempFile implementation is looping, generating new file name, until the file has been created. The file creation of course is delegated to the native file system operation which we may assume is threadsafe..