Hello everyone!
Maybe you have situations in your practice, where WM package try to read some flat file, but can’t do it, because file is ‘busy’ in other process (for example - some other process in this time write data to this file) and WM package is get fatal error… So, my question is - how to check file ‘lock’ status and set some timer for try again to read file later…?
What are you using to read the flat file, and how long are the locks held typically?
The first thing that comes to mind is a Java service that puts the flat file read in a try/catch block within a do/while statement - but this is not the way to go if the locks are held for more than a second or two at a time (since the service chews up a thread the entire time it is whiling).
It may be desirable to avoid file lock issue. If you’re trying to pick up a file while another process is still writing it, then there is a fairly straight-forward approach that has been covered on these forums a few times.
-
Polling process looks for files that match a pattern. For example, all *.dat files. Or any file not starting with X, as another example.
-
Process that is dropping off the file writes the file using a pattern that is not being polled for. For example, foobar.tmp or Xfubar.xml.
-
When the file write is complete, rename the file to a name that matches the pattern being polled. For example, foobar.dat or fubar.xml.
-
The poller will now pick up the files on the next run, with no chance of conflicting with a file still being written to/locked.
This approach works on any OS (file rename are atomic) and is effective whether picking up from a local drive, a network share or an FTP server. You can also get a little sophisticated with the rename–a rename can move the file to another directory too. So you might have a temp directory for process X to write the file, then process X renames it to move to the polling directory (need to be a bit careful on this one–works only if the two directories are on the same physical device).
Hope this helps.