Java. I have two threads. one will be continuously monitoring for some events and based on the events, it will be updating (addition or deletion) a file. the other thread which is a timer task event, will be updating the same file in regular intervals of time. **I want the threads to update the file when the other thread is not accessing the file**. I couldn't use locks as **file updating code part is independent for each thread and in different java classes**. how can i do so? thanks in advance.