简体   繁体   中英

Preventing fetching the same file from FTP server using multiple FTP clients in Java

I have multiple FTP clients that will periodically look for new files on the FTP server. Now, if one of the client fetches a file for further processing, I want to move it to some other directory (say processed directory). Now the problem is of concurrency, how can we manage such that no two clients process the same file at the same time. One file should only be processed by only one client.

I can't think of how to handle this. Is there any tool that can be used in this case or should I write a piece of code on server side that will notify me of new files that arrive?

Thanks in advance.

Move/rename the file first. That's an atomic operation that only one client can succeed with.

The client that succeeds, can then download the file from the new location/name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM