Multithreaded access to file

后端 未结 7 952
[愿得一人]
[愿得一人] 2020-12-30 08:04

We have a multi threaded java program. Multiple-threads will write to a file, and one thread will read from that file. I am looking for some design ideas. Is synchronization

7条回答
  •  长情又很酷
    2020-12-30 08:21

    Once multiple Threads access shared data then Synchronization is necessary. If multiple threads write to the same file without some form of locking, then potentially you will end up with a lost update problem.

    Reading is not as big an issue in all circumstances so you need to consider...if a thread is reading the file and at the same time another thread updates the file, does the reading thread need to know about the change? If so you need to lock the file for the reading thread also.

提交回复
热议问题