/** * Create the lock file if it doesn't already exist and lock it with * an exclusive lock. * * @param lockFile the name of the lock file * @throws IOException if the file has already been locked or an I/O error * occurs. */ private LockFile(File lockFile) throws IOException { this.lockFile = lockFile; if (lockFile == null) { throw new IllegalArgumentException("Parameter lockFile is null"); } lockInternal(lockFile); try { raf = new RandomAccessFile(lockFile, "rw"); fc = raf.getChannel(); fl = fc.tryLock(); if (fl == null) throw new IOException("Lock file busy: " + lockFile); } finally { if (fl == null) { // An exception must have occurred. release(); } } }