locked files : Java Glossary

locked files
Ordinary java.io does not support file locking. However Windows lets you lock files for exclusive use. In particular, it locks active DLL (Dynamic Link Library)s from modification or deletion. The only way to get rid of such a file is to wait until the next reboot, and before the file in put into use again, and modify or delete it. You will see installers and uninstallers doing this. You can do it yourself manually with Microsoft’s Inuse Utility.

When a program crashes, Windows sometimes fails to release its file locks. Usually rebooting clears them.

OH.exe, part of the XP resource toolkit will tell you which process has locked a file.

Starting with Java 1.4, there is the java.nio.channels. FileLock class. File locks are held on behalf of the entire Java virtual machine. They are not suitable for controlling access to a file by multiple threads within the same virtual machine. There are so many excuses in the docs for how they are not guaranteed to work, they sound all but useless.

You can roll your own primitive locks using the presence or absence of tiny locked-indicator files to indicate when a main file is in-use. Use File. createNewFile which as the nice property it atomically creates a new, empty file named if and only if a file with this name does not yet exist. You can even implement such a scheme in bat file language to prevent more than one instancte of any app from running at once. See the bat files to control the bulk email program.

Oracle’s Javadoc on FileLock class : available:

CMP homejump to top You can get the freshest copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/jgloss/lockedfiles.html J:\mindprod\jgloss\lockedfiles.html
logo
Please email your , letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email. If you want your message, your name or email kept confidential, not considered for public posting, please explicitly specify that. Unless you state otherwise, I will treat your message as a letter to the editor that I may or may not publish in the feedback section. After that, it will be too late to retract it. If you disagree with something I said, please quote it and cite the web page where you found it, tell me why you think it is wrong, and, if possible, provide some supporting evidence. Threatening to kill me or spouting obscenities has yet to persuade me to change my mind.
mindprod.com IP:[65.110.21.43]
view BlogYour face IP:[38.107.179.212]
You are visitor number 10,868.