Home > Back-end >  Process synchronization problem.
Process synchronization problem.

Time:12-08

Now there are two process, to monitor a directory at the same time, each process to do the same, the specific process is as follows:
1 scan folder, will scan the file name in a list,
2 to traverse the list, to copy files to another directory, finish every kao a just delete the original,

Request each file copy only once, now can only be a process execution,

So to implement this function with the filelock,

For (,,,,,,) {
The lock=filelock. Trylock ();
If (lock==null) {
continue;
}
}

But when the test found that some file should be carried out twice, what reason is this excuse me? Is due to want to delete the file, if it is for this reason, how to handle it?
Thank you very much!

CodePudding user response:

Since you can only be a process execution, you lock lock block in the whole process of outside,

 
If (lock. TryLock ()) {/* process block */}

CodePudding user response:

You are two processes to operate, you lock is unable to lock the resources across processes,

You lock can only work within the process,

You can two processes divided operation, such as process 1 handle file creation time last seconds is an odd number of documents, process two processing file creation time even the final seconds of the file,

CodePudding user response:

There are those who know?

CodePudding user response:

https://blog.csdn.net/weixin_43476969/article/details/103991634
You can refer to,
  • Related