In the FileChannel mentioned in the previous section, the Lock ()/trylock () method is available to obtain a file lock Filelock object, which locks the file, where the file lock is a process-level lock, not a thread lock.
The lock () method is a blocking test, and when the method is called and the file lock is not available, the program blocks.
The Trylock () method is a non-blocking locking method that returns the file lock if a file lock is obtained, otherwise NULL is returned.
File locks are divided into shared and exclusive locks, and when the third argument of the Lock/trylock method indicates that the lock is a shared lock, a shared lock allows multiple cities to read the file, but prevents other processes from obtaining an exclusive lock on the file, which by default is False, which is an exclusive lock.
Note: 1, the file lock is held by the Java Virtual machine, if two Java programs run with the same Java virtual machine, you can not lock the same file
2. File lock on some platforms is not mandatory, so it does not work.
Java Core Learning (19) Javanio Framework---file lock