Code example for FileChannel

Methods: tryLock

0
     * @throws IOException if an error occurred while trying to lock 
     */ 
    public boolean acquire() throws IOException { 
        lockStream = new FileOutputStream(lockFile);
        lockChannel = lockStream.getChannel();
        lock = lockChannel.tryLock();
        return null != lock;
 
    } 
 
    /** 
     * Releases the lock 
     * 
     * @throws IOException if an error occurred while trying to unlock 
     */ 
    public void release() throws IOException { 
        if (lock.isValid()) {
            lock.release();
        } 
        if (lockStream != null) {