java.nio.channels.FileLock.close()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(5.5k)|赞(0)|评价(0)|浏览(164)

本文整理了Java中java.nio.channels.FileLock.close()方法的一些代码示例,展示了FileLock.close()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileLock.close()方法的具体详情如下:
包路径:java.nio.channels.FileLock
类名称:FileLock
方法名:close

FileLock.close介绍

[英]Calls #release for AutoCloseable.
[中]呼叫#释放自动关闭。

代码示例

代码示例来源:origin: Netflix/genie

/**
 * {@inheritDoc}
 */
@Override
public void close() throws IOException {
  //FileChannel.close closes the nioFileLock. Closing
  //it explicitly, else findbugs rule URF_UNREAD_FIELD is violated
  nioFileLock.close();
  fileChannel.close();
}

代码示例来源:origin: jeremylong/DependencyCheck

final String current = file.readLine();
if (current != null && !current.equals(magic)) {
  lock.close();
  lock = null;
  LOGGER.debug("Another process obtained a lock first ({})", Thread.currentThread().getName());

代码示例来源:origin: apache/incubator-gobblin

boolean result = true;
try {
  fileLock.close();
  fileLock = null;
  isLocked.set(false);

代码示例来源:origin: cojen/Tupl

@Override
  public void close() throws IOException {
    if (mLock != null) {
      mLock.close();
    }
    if (mRaf != null) {
      mRaf.close();
    }
  }
}

代码示例来源:origin: apache/activemq-artemis

public static void unlock() {
 try {
   if (serverLockFile != null) {
    serverLockFile.close();
    serverLockFile = null;
   }
   if (serverLockLock != null) {
    serverLockLock.close();
    serverLockLock = null;
   }
 } catch (Exception ignored) {
 }
}

代码示例来源:origin: NemProject/nem.core

@Override
  public void close() throws IOException {
    if (null != this.lock) {
      this.lock.close();
    }
    this.file.close();
  }
}

代码示例来源:origin: com.truward.tupl/tupl

@Override
  public void close() throws IOException {
    if (mLock != null) {
      mLock.close();
    }
    if (mRaf != null) {
      mRaf.close();
    }
  }
}

代码示例来源:origin: com.netflix.genie/genie-agent

/**
 * {@inheritDoc}
 */
@Override
public void close() throws IOException {
  //FileChannel.close closes the nioFileLock. Closing
  //it explicitly, else findbugs rule URF_UNREAD_FIELD is violated
  nioFileLock.close();
  fileChannel.close();
}

代码示例来源:origin: org.cojen/tupl

@Override
  public void close() throws IOException {
    if (mLock != null) {
      mLock.close();
    }
    if (mRaf != null) {
      mRaf.close();
    }
  }
}

代码示例来源:origin: org.apache.activemq/artemis-cli

public static void unlock() {
 try {
   if (serverLockFile != null) {
    serverLockFile.close();
    serverLockFile = null;
   }
   if (serverLockLock != null) {
    serverLockLock.close();
    serverLockLock = null;
   }
 } catch (Exception ignored) {
 }
}

代码示例来源:origin: nemtech/nem2-sdk-java

@Override
  public void close() throws IOException {
    if (null != this.lock) {
      this.lock.close();
    }
    this.file.close();
  }
}

代码示例来源:origin: org.sonatype.nexus.assemblies/nexus-branding

public synchronized void release() {
  if (lock != null) {
   try {
    lock.close();
   }
   catch (Exception e) {
    // ignore
   }
   lock = null;
  }

  if (lockFile != null) {
   try {
    lockFile.close();
   }
   catch (Exception e) {
    // ignore
   }
   lockFile = null;
  }
 }
}

代码示例来源:origin: com.qwazr/qwazr-search

@Override
  public void deleteOldFiles() throws IOException {
    for (String fileToDelete : filesToDelete) {
      final Path pathToDelete = targetDirectoryPath.resolve(fileToDelete);
      if (Files.exists(pathToDelete)) {
        try (final FileChannel fileChannel = FileChannel.open(pathToDelete, StandardOpenOption.WRITE,
            StandardOpenOption.DELETE_ON_CLOSE)) {
          fileChannel.lock().close();
        } catch (FileNotFoundException e) {
          //That's ok
        }
        if (Files.exists(pathToDelete))
          throw new IOException("Can't delete the file: " + pathToDelete);
      }
    }
  }
}

代码示例来源:origin: baratine/baratine

synchronized void unlock()
{
 FileChannel osFile = _osFile;
 _osFile = null;
 
 FileLock lock = _lock;
 _lock = null;
 
 if (lock != null) {
  try {
   lock.close();
  } catch (Exception e) {
   log.log(Level.FINEST, e.toString(), e);
  }
 }
 
 if (osFile != null) {
  try {
   osFile.close();
  } catch (Exception e) {
   log.log(Level.FINEST, e.toString(), e);
  }
 }
}

代码示例来源:origin: baratine/baratine

synchronized boolean isFree()
 {
  if (_lock != null) {
   return false;
  }
  
  if (! Files.isReadable(_path)) {
   return true;
  }
  
  try (FileOutputStream fOs = (FileOutputStream) Files.newOutputStream(_path)) {
   FileLock lock = fOs.getChannel().tryLock();
   
   if (lock != null) {
    lock.close();
    
    return true;
   }
   else {
    return false;
   }
  } catch (Exception e) {
   log.finer(_path + ": isFree " + e);
   log.log(Level.FINEST, e.toString(), e);
   return true;
  }
 }
}

代码示例来源:origin: de.mhus.lib/mhu-lib-core

public static void releaseLock(FileLock lock) {
  try {
    FileChannel channel = lock.channel();
    lock.close();
    channel.close();
  } catch (IOException e) {
    log.d(e);
  }
}

代码示例来源:origin: org.apache.bookkeeper/cpu-affinity

return () -> {
  finalLock.close();
  finalChannel.close();
  finalFile.close();

代码示例来源:origin: dev.rico/rico-core

public void instanceCheck() {
  final List<ShutdownTask> shutdownRunnables = new ArrayList();
  shutdownRunnables.add(() -> Files.deleteIfExists(lockFile));
  try {
    Files.createDirectories(lockFile.getParent());
    final RandomAccessFile randomAccessFileForLock = new RandomAccessFile(lockFile.toFile(), "rw");
    shutdownRunnables.add(() -> randomAccessFileForLock.close());
    final FileLock fileLock = randomAccessFileForLock.getChannel().tryLock();
    if(fileLock == null) {
      throw new IllegalStateException("Another application is already running!");
    }
    shutdownRunnables.add(() -> fileLock.close());
  } catch (Exception e) {
    throw new RuntimeException("Instance checker went wrong!", e);
  } finally {
    final Thread shutdownHookThread = new Thread(() -> {
      shutdownRunnables.stream()
          .collect(Collectors.toCollection(LinkedList::new))
          .descendingIterator()
          .forEachRemaining(task -> {
            try {
              task.run();
            } catch (Exception e) {
              e.printStackTrace();
            }
          });
    });
    Runtime.getRuntime().addShutdownHook(shutdownHookThread);
  }
}}

代码示例来源:origin: cojen/Tupl

@Override
  public void close() throws IOException {
    mMetadataLatch.acquireExclusive();
    try {
      acquireExclusive();
      try {
        if (mClosed) {
          return;
        }

        mClosed = true;

        mMetadataLock.close();

        mMetadataFile.close();
        Utils.delete(mMetadataBuffer);

        for (Object key : mTermLogs) {
          ((TermLog) key).close();
        }
      } finally {
        releaseExclusive();
      }
    } finally {
      mMetadataLatch.releaseExclusive();
    }

    mWorker.join(true);
  }
}

代码示例来源:origin: yahoo/HaloDB

dbLock.close();

相关文章