开发者

What will happen if two different programs try to write to the same file simulatneously?

  1. Wha开发者_Go百科t will happen if two different programs try to write to the same file simultaneously?

  2. Will one of the programs experience a file lock error?

  3. How should programs be designed to handle this scenario?


When the second app (or thread) try to open the file for writing it would throw IO exception.. simple..


say you have user A and user B, what you can do is, let both of them modify the content, there will be a small difference in time however "simultaneous" you want it to be, so check which user has "submitted" the changes first, save those changes and prompt a smart message to the next user saying "file has been updated, check changes before.. blah blah".


Use FileLock to avoid IO Exception when file is being accessed by multiple threads.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜