camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bacar <>
Subject Re: FileUtil.createNewFile race condition issue
Date Wed, 18 Feb 2015 10:34:41 GMT
Here's a simple test which demonstrates the issue:

It spins up 2 threads which attempt File.createNewFile on the same file,
catch IOExceptions, and check for file existence.

After several rounds of the two threads fighting over the file (with
createNewFile returning false if the other thread still has 'ownership'), I
eventually get:

1: failed to create file.
1: creating file
1: failed to create file.
1: creating file
2: deleted file
2: creating file
1: exception! File exists? true Access is denied
	at Method)
2: created file.
2: deleting file
2: deleted file

Note that:
- the last thing that thread 1 and thread 2 both did before the exception
was to attempt to create the file.
- at the point the exception occurred in thread 1, the file did exist
- however we can see from the line immediately following the exception that
thread _2_ created that file, ie thread 2 has ownership; thread 1 _cannot_
assume that it owns the file merely because it exists.

View this message in context:
Sent from the Camel Development mailing list archive at

View raw message