当前位置: 首页>>代码示例>>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;未经允许,请勿转载。