开发者

how can we achieve second application read that file when first application not modifying it

i have two application first application is bash second is java

which one of them is periodically deleting and recreating a specific file (first)

the other one is also periodically reading this file and process it in it's own logic (second)

how can we achieve se开发者_运维知识库cond application read that file when first application not modifying it

my aim is to force second app read the file only when content of file fully written inside it

how can achieve this goal ?


Your second app can attempt to open the file with read-write permissions. Since that should (in most OSes, I think) block if another app has the file open for write, the second app can be sure the the first app has finished its write and closed the file.

Of course, you have to also handle the case that the first app starts deleting and recreating the file again before the second app can acquire a lock; so either the first app should synchronize off a different file that is created and locked by the second app, or you have to 'hope' that the timing stays consistent and separated enough that that won't happen. Having a third, supervisory application that manages the synchronization of the two apps may work better?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜