Class LockFile

  • public class LockFile
    extends Object
    Lock files are used to protect files against concurrent access.

    Using lock files is often declared as deprecated, but I still use them sometimes, because it works fine on all filesystem.

    Stefan Frings,
    • Constructor Detail

      • LockFile

        public LockFile()
    • Method Detail

      • lock

        public static void lock​(File file,
                                int seconds)
                         throws IOException,
        Create a lock file. If the lock file does already exist, this method waits a while.
        file - File that shall be locked. The lock file will have the same name with additional suffix ".lock".
        seconds - Maximum seconds to wait
        IOException - In case of an I/O error
        InterruptedException - If the waiting loop got interrupted.
      • release

        public static void release​(File file)
        Delete a lock file. Nothing happens if the file does not exist.
        file - The lock file to delete.