當前位置: 首頁>>代碼示例>>Java>>正文


Java Lock.unlock方法代碼示例

本文整理匯總了Java中java.util.concurrent.locks.Lock.unlock方法的典型用法代碼示例。如果您正苦於以下問題:Java Lock.unlock方法的具體用法?Java Lock.unlock怎麽用?Java Lock.unlock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.concurrent.locks.Lock的用法示例。


在下文中一共展示了Lock.unlock方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: put

import java.util.concurrent.locks.Lock; //導入方法依賴的package包/類
/**
 * Adds the given object to the store. Technically this method only adds the object if it does not already exist in
 * the store. If it does this method simply increments the reference count of the object.
 * 
 * @param object the object to add to the store, may be null
 * 
 * @return the index that may be used to later retrieve the object or null if the object was null
 */
public String put(T object) {
    if (object == null) {
        return null;
    }

    Lock writeLock = rwLock.writeLock();
    writeLock.lock();
    try {
        String index = Integer.toString(object.hashCode());

        StoredObjectWrapper objectWrapper = objectStore.get(index);
        if (objectWrapper == null) {
            objectWrapper = new StoredObjectWrapper(object);
            objectStore.put(index, objectWrapper);
        }
        objectWrapper.incremementReferenceCount();

        return index;
    } finally {
        writeLock.unlock();
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:31,代碼來源:IndexingObjectStore.java

示例2: action

import java.util.concurrent.locks.Lock; //導入方法依賴的package包/類
public final void action(final MapleClient c, final byte mode, final byte type, final int selection) {
    if (mode != -1) {
        final NPCConversationManager cm = cms.get(c);
        if (cm == null || cm.getLastMsg() > -1) {
            return;
        }
        final Lock lock = c.getNPCLock();
        lock.lock();
        try {
            if (cm.pendingDisposal) {
                dispose(c);
            } else {
                c.setClickedNPC();
                cm.getIv().invokeFunction("action", mode, type, selection);
            }
        } catch (final ScriptException | NoSuchMethodException e) {
            System.err.println("Error executing NPC script. NPC ID : " + cm.getNpc() + ":" + e);
            dispose(c);
            e.printStackTrace();
        } finally {
            lock.unlock();
        }
    }
}
 
開發者ID:ergothvs,項目名稱:Lucid2.0,代碼行數:25,代碼來源:NPCScriptManager.java

示例3: interruptibleWriterView

import java.util.concurrent.locks.Lock; //導入方法依賴的package包/類
static Writer interruptibleWriterView(final StampedLock sl,
                                      final long timeout,
                                      final TimeUnit unit,
                                      final Phaser gate) {
    return new Writer("InterruptibleWriterView") { public void run() {
        if (gate != null ) toTheStartingGate(gate);
        Lock wl = sl.asWriteLock();
        try {
            if (timeout < 0)
                wl.lockInterruptibly();
            else
                wl.tryLock(timeout, unit);
            stamp(1L);  // got the lock
            check(!sl.isReadLocked());
            check(sl.isWriteLocked());
        } catch (Throwable x) { thrown(x);
        } finally { if (stamp() != 0L) wl.unlock(); } }};
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:Basic.java

示例4: getRealm

import java.util.concurrent.locks.Lock; //導入方法依賴的package包/類
/**
 * Return the Realm with which this Container is associated.  If there is
 * no associated Realm, return the Realm associated with our parent
 * Container (if any); otherwise return <code>null</code>.
 */
@Override
public Realm getRealm() {

    Lock l = realmLock.readLock();
    try {
        l.lock();
        if (realm != null)
            return (realm);
        if (parent != null)
            return (parent.getRealm());
        return null;
    } finally {
        l.unlock();
    }
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:21,代碼來源:ContainerBase.java

示例5: get

import java.util.concurrent.locks.Lock; //導入方法依賴的package包/類
/**
 * Gets a registered object by its index.
 * 
 * @param index the index of an object previously registered, may be null
 * 
 * @return the registered object or null if no object is registered for that index
 */
public T get(String index) {
    if (index == null) {
        return null;
    }

    Lock readLock = rwLock.readLock();
    readLock.lock();
    try {
        StoredObjectWrapper objectWrapper = objectStore.get(index);
        if (objectWrapper != null) {
            return objectWrapper.getObject();
        }

        return null;
    } finally {
        readLock.unlock();
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:26,代碼來源:IndexingObjectStore.java

示例6: runWithLock

import java.util.concurrent.locks.Lock; //導入方法依賴的package包/類
@SneakyThrows
public static <R, E extends Exception> R runWithLock(Lock lock, long maxWaitTime, ReturnableTask<R, E> task) {
    log.info("Try to lock git repository");
    if (lock.tryLock(maxWaitTime, TimeUnit.SECONDS)) {
        log.info("Git repository locked");
        try {
            return task.execute();
        } finally {
            log.info("Try to unlock git repository");
            lock.unlock();
            log.info("Git repository unlocked");
        }
    } else {
        throw new IllegalMonitorStateException("Git repository locked");
    }
}
 
開發者ID:xm-online,項目名稱:xm-ms-config,代碼行數:17,代碼來源:LockUtils.java

示例7: setDescription

import java.util.concurrent.locks.Lock; //導入方法依賴的package包/類
public void setDescription(String description) {
    Lock l = mBeanInfoLock.writeLock();
    l.lock();
    try {
        this.description = description;
        this.info = null;
    } finally {
        l.unlock();
    }
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:11,代碼來源:ManagedBean.java

示例8: testWriteLockWriteUnlock

import java.util.concurrent.locks.Lock; //導入方法依賴的package包/類
@Test
public void testWriteLockWriteUnlock() {
  final ReadWriteLock rwl = new CountingReadWriteLock();
  final Lock w = rwl.writeLock();
  w.lock();
  w.unlock();
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:8,代碼來源:CountingReadWriteLockTest.java

示例9: setName

import java.util.concurrent.locks.Lock; //導入方法依賴的package包/類
public void setName(String name) {
    Lock l = mBeanInfoLock.writeLock();
    l.lock();
    try {
        this.name = name;
        this.info = null;
    } finally {
        l.unlock();
    }
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:11,代碼來源:ManagedBean.java

示例10: incrementBy

import java.util.concurrent.locks.Lock; //導入方法依賴的package包/類
@VisibleForTesting
void incrementBy(long offset, Instant startTimestamp, ImmutableList<String> labelValues) {
  Lock lock = valueLocks.get(labelValues);
  lock.lock();

  try {
    values.addAndGet(labelValues, offset);
    valueStartTimestamps.putIfAbsent(labelValues, startTimestamp);
  } finally {
    lock.unlock();
  }
}
 
開發者ID:google,項目名稱:java-monitoring-client-library,代碼行數:13,代碼來源:Counter.java

示例11: onOpen

import java.util.concurrent.locks.Lock; //導入方法依賴的package包/類
@Override
public void onOpen(WebSocketConnection client) {
    Lock lock = poolLock.writeLock();
    lock.lock();
    try {
        pool.add(client);
        if (latestStatic != null) client.send(latestStatic);
        if (latestDynamic != null) client.send(latestDynamic);
        System.out.println(String.format("[ MONITOR ] %d viewer(s) connected", pool.size()));
    } finally {
        lock.unlock();
    }
}
 
開發者ID:agentcontest,項目名稱:massim,代碼行數:14,代碼來源:Monitor.java

示例12: addObligationhandler

import java.util.concurrent.locks.Lock; //導入方法依賴的package包/類
/**
 * Adds an obligation handler to the list of registered handlers
 * 
 * This method waits until a write lock is obtained for the set of registered obligation handlers.
 * 
 * @param handler the handler to add to the list of registered handlers.
 */
public void addObligationhandler(BaseObligationHandler handler) {
    if (handler == null) {
        return;
    }

    Lock writeLock = rwLock.writeLock();
    writeLock.lock();
    try {
        obligationHandlers.add(handler);
    } finally {
        writeLock.unlock();
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:21,代碼來源:ObligationService.java

示例13: testLock

import java.util.concurrent.locks.Lock; //導入方法依賴的package包/類
/**
 * Case1: Test for lock()
 */
@Test
public void testLock() {
    // generate lock in a free way, you should specify lock type, target, lease time, lease unit
    Lock lock = lockGenerator.gen("FAKE_LOCK", "A_TARGET", 1, TimeUnit.SECONDS);

    try {
        lock.lock();
        doYourWork();

    } finally {
        // Make sure unlock in the finally code block
        lock.unlock();
    }
}
 
開發者ID:baidu,項目名稱:dlock,代碼行數:18,代碼來源:DLockSimpleTest.java

示例14: getRealmInternal

import java.util.concurrent.locks.Lock; //導入方法依賴的package包/類
protected Realm getRealmInternal() {
    Lock l = realmLock.readLock();
    try {
        l.lock();
        return realm;
    } finally {
        l.unlock();
    }
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:10,代碼來源:ContainerBase.java

示例15: withLock

import java.util.concurrent.locks.Lock; //導入方法依賴的package包/類
public static <T, R> R withLock(Lock lock, Function<T, R> fun, T in) {
	lock.lock();
	try {
		return fun.apply(in);
	} finally {
		lock.unlock();
	}
}
 
開發者ID:opensecuritycontroller,項目名稱:osc-core,代碼行數:9,代碼來源:Locking.java


注:本文中的java.util.concurrent.locks.Lock.unlock方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。