tags:

views:

20

answers:

1

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 second 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 ?

A: 

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?

Mikeb