java - Acquire a lock on a file -
i want acqeuire lock on file when threo read gets started on specific file ,so no other application can read file has been locked , want release lock file when thread terminates. you can acquire filelock via filechannel . obtain filechannel: in release file channel can obtained existing fileinputstream , fileoutputstream , or randomaccessfile object invoking object's getchannel method, returns file channel connected same underlying file. however, java doesn't have control on type of file locking os offers , therefore recommendation of api use lock if advisory file lock. whether or not lock prevents program accessing content of locked region system-dependent , therefore unspecified. native file-locking facilities of systems merely advisory, meaning programs must cooperatively observe known locking protocol in order guarantee data integrity. on other systems native file locks mandatory, meaning if 1 program locks region of file other programs prevente...