Anil
Anil

Reputation: 1488

Why do we need file locks in file channel as operations are not concurrently accessed?

In java.nio.channels.FileChannel any concurrent operations are blocked. It seems all operations are synchronized, but why do we use file lock to lock the file explicitly?

Upvotes: 1

Views: 273

Answers (1)

Peter Lawrey
Peter Lawrey

Reputation: 533492

The file lock, locks the file from access by all programs.

The synchronized access to the FileChannel locks access to that object within the same program. If you use another FileChannel you can access the same file in a different thread.

Upvotes: 2

Related Questions