本文整理汇总了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();
}
}
示例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();
}
}
}
示例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(); } }};
}
示例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();
}
}
示例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();
}
}
示例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");
}
}
示例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();
}
}
示例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();
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例14: getRealmInternal
import java.util.concurrent.locks.Lock; //导入方法依赖的package包/类
protected Realm getRealmInternal() {
Lock l = realmLock.readLock();
try {
l.lock();
return realm;
} finally {
l.unlock();
}
}
示例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();
}
}