Link to home
Start Free TrialLog in
Avatar of abuyusuf35
abuyusuf35

asked on

File Locking in Java

I have 2 threads polling the same directory for files to process - once a thread sees a file it will read the file name and start processing it - it keeps the file name in a cache so that it does not process it again. Once the middle tier has finished processing the file it signals the database to start processing it. This is through a status change of the file in the database itself - the database is polling this status and once it changes it starts processing.

The issue is there could be another thread polling the same directory - I need a way for a thread to lock the file once it has started processing it. How can I do this in Java in an O/S independent fashion ?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of ksivananth
ksivananth
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of abuyusuf35
abuyusuf35

ASKER

Thanks for the response - my understanding is that the behaviour of this API is not consistent on all platforms - is that correct ?
yes, but as long as all your processes aquires the lock, it should be fine in all platforms!
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I recommend splitting points between ksivanath's comment (35084258) and my comment (35109520) as both represent valid solutions to the problem.
Avatar of Dirk Haest
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.