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.

    Author:
    Stefan Frings, http://stefanfrings.de/javautils
    • Constructor Detail

      • LockFile

        public LockFile()
    • Method Detail

      • lock

        public static void lock​(File file,
                                int seconds)
                         throws IOException,
                                InterruptedException
        Create a lock file. If the lock file does already exist, this method waits a while.
        Parameters:
        file - File that shall be locked. The lock file will have the same name with additional suffix ".lock".
        seconds - Maximum seconds to wait
        Throws:
        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.
        Parameters:
        file - The lock file to delete.