When running the multiple instances of the above class concurrently 1) from different JVM 2) against the same directory 3) with different instance id (so that multiple instances will not operate on the same file) the line 28 file.renameTo() method returns false, even though when the file name is successfully renamed. However, when Thread.sleep() method call in line 21 is commented out, the problem does not occur anymore. Any idea why the return value of file.renameTo method call indicates a failure when in fact it really worked? Could this be a coding issue, JVM issue (Java 1.3.1), or OS issue (NT 4.0)? Any insights are greatly appreciated. Jiang [ April 02, 2004: Message edited by: Jiang Lin ]
Any idea why the return value of file.renameTo method call indicates a failure when in fact it really worked? Are you sure it really worked? One reason renameTo() may fail is if there's already a file matching the new name. If you run your program more than once, maybe the file got moved correctly the first time. On subsequent attempts the rename fails, because the previously moved file is still there. But it looks as though you've moved it successfully, because there's a file there where you expect the renamed file to be. Try checking if (newFile.exists()) in your method.
"I'm not back." - Bill Harding, Twister
Joined: Mar 03, 2004
Thanks very much, Jim. That was exactly the problem. There was a bug in instantiating the file filer at line 10, so the instances "saw" the files that were supposed to belong to others and processed them before the supposed owner picked them up... Thanks again. I very much appreciate your help. Jiang Lin