Code example for FileLock

Methods: isValid, release

0
        assertTrue(tmpLock.isValid());
        tmpLock.release();
 
        // Acquire another valid lock -- and don't release it yet 
        FileLock lock = readOnlyChannel.tryLock(10, 788, true);
        assertTrue(lock.isValid());
 
        // Overlapping locks are illegal 
        try { 
            readOnlyChannel.tryLock(1, 23, true);
            fail("Acquiring an overlapping lock should fail.");
        } catch (OverlappingFileLockException ex) {
            // Expected 
        } 
 
        // Adjacent locks are legal 
        FileLock adjacentLock = readOnlyChannel.tryLock(1, 3, true);
        assertTrue(adjacentLock.isValid());
        adjacentLock.release();
 
        // Release longer lived lock 
        lock.release();
    } 
}