Wouldn't you be able to use a synchronized block on the given file?

nonetheless, Apache file transactions lib might be useful here.