Hi Its actually a bit tricky to detect if a file is locked by another process or not. Although we have the java.nio API it seems to not work consistent across OS's. And I actually think its stated in the docs somewhere, that this can be the case.
Also note that NIO locks is JVM wide, which means from an unit test you cannot lock a file by one thread, and from the same JVM see the file lock. And if you forget to unlock the NIO lock, that file is locked until you restart the JVM. Can be a caveat for big app servers, if you have a rouge app holding a lock. Then you can try to obtain the lock on the file by trying to rename it before reading, if you can rename then you assume the other party is not currently writing to it. But I think some OS and apps may allow the OS to rename a file which currently is being written by that app. That leaves you with checking the file modification and timestamp and wait until its "steady". But NIO 2 should have a file watcher API. I assume it may be better at providing notifications when a file has been finished writing. So we can wait for Java 7 :) On Thu, Oct 7, 2010 at 1:07 AM, Craig Tataryn <[email protected]> wrote: > Has anyone had any luck using a readLock strategy other than "changed"? I've > tried them all, and "changed" seems to be the only one that works > consistently when I'm copying a large file into a directory the File > Component is monitoring. > > All other's allow the File Component to execute before the file is completely > copied into the directory. > > $mvn -X --version > Apache Maven 3.0-beta-3 (r990787; 2010-08-30 07:44:03-0500) > Java version: 1.6.0_20 > Java home: /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home > Default locale: en_US, platform encoding: MacRoman > OS name: "mac os x" version: "10.6.4" arch: "x86_64" Family: "mac" > > Craig. > > -- > Craig Tataryn > site: http://www.basementcoders.com/ > podcast: http://www.basementcoders.com/?feed=podcast > itunes: http://itunes.apple.com/podcast/the-basement-coders > irc: ThaDon on freenode #basementcoders, ##wicket, #papernapkin > twitter: craiger > > -- Claus Ibsen Apache Camel Committer Author of Camel in Action: http://www.manning.com/ibsen/ Open Source Integration: http://fusesource.com Blog: http://davsclaus.blogspot.com/ Twitter: http://twitter.com/davsclaus
