public boolean LockExclusive(File targetFile) { if (targetFile == null) { return false; } try { File lockFile = new File(targetFile.getParentFile().getAbsolutePath().concat("/lock")); if (!lockFile.exists()) { lockFile.createNewFile(); } RandomAccessFile randomAccessFile = new RandomAccessFile(lockFile.getAbsolutePath(), "rw"); FileChannel channel = randomAccessFile.getChannel(); java.nio.channels.FileLock lock = channel.lock(); if (!lock.isValid()) { return false; } RefCntInc(lockFile.getAbsolutePath(), lock, randomAccessFile, channel); return true; } catch (Exception e) { return false; } }
public boolean LockExclusive(File targetFile) { if (targetFile == null) { return false; } try { File lockFile = new File(targetFile.getParentFile().getAbsolutePath().concat("/lock")); if (!lockFile.exists()) { lockFile.createNewFile(); } RandomAccessFile randomAccessFile = new RandomAccessFile(lockFile.getAbsolutePath(), "rw"); FileChannel channel = randomAccessFile.getChannel(); java.nio.channels.FileLock lock = channel.lock(); if (!lock.isValid()) { return false; } RefCntInc(lockFile.getAbsolutePath(), lock, randomAccessFile, channel); return true; } catch (Exception e) { return false; } }
public boolean LockExclusive(File targetFile) { if (targetFile == null) { return false; } try { File lockFile = new File(targetFile.getParentFile().getAbsolutePath().concat("/lock")); if (!lockFile.exists()) { lockFile.createNewFile(); } RandomAccessFile randomAccessFile = new RandomAccessFile(lockFile.getAbsolutePath(), "rw"); FileChannel channel = randomAccessFile.getChannel(); java.nio.channels.FileLock lock = channel.lock(); if (!lock.isValid()) { return false; } RefCntInc(lockFile.getAbsolutePath(), lock, randomAccessFile, channel); return true; } catch (Exception e) { return false; } }