mrAlmond
mrAlmond

Reputation: 403

Android FileLock...how to lock files from different processes

I need to lock a text file that is read and written from three different android applications...so different processes.

I've tried to use channel lock() (exclusive mode) when writing and lock(0L, Long.MAX_VALUE, true) (shared) when reading the file.

Unfortunately this approach does not work...lock is always acquired when reading also when the writing lock is not yet released.

Are there suitable and working examples to solve this issue? Am I doing something wrong?

Upvotes: 2

Views: 2430

Answers (1)

mrAlmond
mrAlmond

Reputation: 403

Finally I've solved it! FileLocks are ok...my problem is that I was writing to an xml file using storeToXml that probably creates a brand new file...so new file descriptor is created and the lock property was probably lost. Now I'm locking another dummy file instead of the one I'm reading and writing and everything works as expected.

Upvotes: 1

Related Questions