javaandroidfilequeuesynchronize

how to avoid synchronization issue in writing contents to file - Java ( android)


I have a requirement which updates the file contents from multiple operation which can occur at the same time.

I need to queue each request and the change the contents of the file for each request one by one.

I am using android broadcast receiver which receives the events for changing the file contents.

How can I queue this events and make changes to file one after the other request.

Please provide some suggestion or if possible please provide any links that I can refer.


Solution

  • I have used executor with single thread. When event is received, we can post runnable to the executor. As the pool has 1 thead, these tasks will run in sequence.