本文整理了Java中java.nio.channels.FileLock.release()
方法的一些代码示例,展示了FileLock.release()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileLock.release()
方法的具体详情如下:
包路径:java.nio.channels.FileLock
类名称:FileLock
方法名:release
[英]Releases this particular lock on the file. If the lock is invalid then this method has no effect. Once released, the lock becomes invalid.
[中]释放文件上的此特定锁。如果锁无效,则此方法无效。一旦释放,锁就会失效。
代码示例来源:origin: neo4j/neo4j
protected void releaseLock() throws IOException
{
storeLockFileLock.release();
storeLockFileLock = null;
}
}
代码示例来源:origin: com.h2database/h2
@Override
public void release() throws IOException {
base.release();
}
代码示例来源:origin: com.h2database/h2
/**
* Release the file lock.
*/
public synchronized void releaseLock() {
if (file != null && lock != null) {
try {
lock.release();
} catch (Exception e) {
// ignore
}
lock = null;
}
}
代码示例来源:origin: robovm/robovm
/**
* Calls {@link #release} for {@code AutoCloseable}.
*
* @since 1.7
*/
public final void close() throws IOException {
release();
}
代码示例来源:origin: Tencent/tinker
@Override
public void close() throws IOException {
try {
if (fileLock != null) {
fileLock.release();
}
} finally {
if (outputStream != null) {
outputStream.close();
}
}
}
}
代码示例来源:origin: apache/incubator-druid
private void unlockBasePersistDirectory()
{
try {
if (basePersistDirLock != null) {
basePersistDirLock.release();
basePersistDirLockChannel.close();
basePersistDirLock = null;
}
}
catch (IOException e) {
throw Throwables.propagate(e);
}
}
代码示例来源:origin: stanfordnlp/CoreNLP
public synchronized void release() throws IOException {
if (licenses <= 0) { throw new IllegalStateException("Already released all semaphore licenses"); }
licenses -= 1;
if (licenses <= 0) {
if (lock != null) { lock.release(); }
channel.close();
}
}
}
代码示例来源:origin: apache/ignite
/**
* Quietly releases file lock ignoring all possible exceptions.
*
* @param lock File lock. If it's {@code null} - it's no-op.
*/
public static void releaseQuiet(@Nullable FileLock lock) {
if (lock != null)
try {
lock.release();
}
catch (Exception ignored) {
// No-op.
}
}
代码示例来源:origin: stackoverflow.com
FileInputStream in = new FileInputStream(file);
try {
java.nio.channels.FileLock lock = in.getChannel().lock();
try {
Reader reader = new InputStreamReader(in, charset);
...
} finally {
lock.release();
}
} finally {
in.close();
}
代码示例来源:origin: apache/incubator-druid
@LifecycleStop
public void stop() throws Exception
{
parentMonitorExec.shutdown();
synchronized (this) {
if (taskLockFileLock != null) {
taskLockFileLock.release();
}
if (taskLockChannel != null) {
taskLockChannel.close();
}
}
}
}
代码示例来源:origin: graphhopper/graphhopper
public static void main(String[] args) throws IOException {
// trying FileLock mechanics in different processes
File file = new File("tmp.lock");
file.createNewFile();
FileChannel channel = new RandomAccessFile(file, "r").getChannel();
boolean shared = true;
FileLock lock1 = channel.tryLock(0, Long.MAX_VALUE, shared);
System.out.println("locked " + lock1);
System.in.read();
System.out.println("release " + lock1);
lock1.release();
}
代码示例来源:origin: apache/incubator-dubbo
lock.release();
代码示例来源:origin: apache/incubator-dubbo
lock.release();
代码示例来源:origin: apache/incubator-dubbo
lock.release();
代码示例来源:origin: apache/incubator-dubbo
lock.release();
代码示例来源:origin: com.h2database/h2
private void reLock() throws IOException {
if (lock == null) {
return;
}
try {
lock.base.release();
} catch (IOException e) {
// ignore
}
FileLock l2 = channel.tryLock(lock.position(), lock.size(), lock.isShared());
if (l2 == null) {
throw new IOException("Re-locking failed");
}
lock.base = l2;
}
代码示例来源:origin: apache/ignite
@Override public void run() {
try {
RandomAccessFile raf = new RandomAccessFile(file, "r");
System.out.println("Getting lock (parallel thread)...");
FileLock lock = raf.getChannel().lock(0, Long.MAX_VALUE, true);
System.out.println("Obtained lock (parallel thread): " + lock);
lock.release();
}
catch (Throwable e) {
e.printStackTrace();
}
}
});
代码示例来源:origin: apache/ignite
@Override public void run() {
try {
RandomAccessFile raf = new RandomAccessFile(file, "rw");
System.out.println("Getting lock (parallel thread)...");
FileLock lock = raf.getChannel().lock();
System.out.println("Obtained lock (parallel tread): " + lock);
lock.release();
}
catch (Throwable e) {
e.printStackTrace();
}
}
});
代码示例来源:origin: gocd/gocd
@Test
@RunIf(value = EnhancedOSChecker.class, arguments = {EnhancedOSChecker.WINDOWS})
public void shouldThrowExceptionWhenWorkingDirectoryIsNotGitRepoAndItsUnableToDeleteIt() throws Exception {
File fileToBeLocked = new File(workingDir, "file");
RandomAccessFile lockedFile = new RandomAccessFile(fileToBeLocked, "rw");
FileLock lock = lockedFile.getChannel().lock();
try {
git.latestModification(workingDir, new TestSubprocessExecutionContext());
fail("Should have failed to check modifications since the file is locked and cannot be removed.");
} catch (Exception e) {
assertEquals(e.getMessage().trim(), "Failed to delete directory: " + workingDir.getAbsolutePath().trim());
assertEquals(true, fileToBeLocked.exists());
}
finally {
lock.release();
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void ch_tryLock() throws IOException
{
chan( false ).tryLock().release();
}
内容来源于网络,如有侵权,请联系作者删除!