当前位置: 首页>>代码示例>>Java>>正文


Java StampedLock.asReadLock方法代码示例

本文整理汇总了Java中java.util.concurrent.locks.StampedLock.asReadLock方法的典型用法代码示例。如果您正苦于以下问题:Java StampedLock.asReadLock方法的具体用法?Java StampedLock.asReadLock怎么用?Java StampedLock.asReadLock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.locks.StampedLock的用法示例。


在下文中一共展示了StampedLock.asReadLock方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: interruptibleReaderView

import java.util.concurrent.locks.StampedLock; //导入方法依赖的package包/类
static Reader interruptibleReaderView(final StampedLock sl,
                                      final long timeout,
                                      final TimeUnit unit,
                                      final Phaser gate) {
    return new Reader("InterruptibleReaderView") { public void run() {
        if (gate != null ) toTheStartingGate(gate);
        final Lock rl = sl.asReadLock();

        try {
            if (timeout < 0)
                rl.lockInterruptibly();
            else
                rl.tryLock(timeout, unit);
            stamp(1L);  // got the lock
            check(sl.isReadLocked());
            check(!sl.isWriteLocked());
        } catch (Throwable x) { thrown(x);
        } finally { if (stamp() != 0L) rl.unlock(); } }};
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:Basic.java

示例2: testAsReadLock

import java.util.concurrent.locks.StampedLock; //导入方法依赖的package包/类
/**
 * asReadLock can be locked and unlocked
 */
public void testAsReadLock() throws Throwable {
    StampedLock sl = new StampedLock();
    Lock lock = sl.asReadLock();
    for (Action locker : lockLockers(lock)) {
        locker.run();
        assertTrue(sl.isReadLocked());
        assertFalse(sl.isWriteLocked());
        assertEquals(1, sl.getReadLockCount());
        locker.run();
        assertTrue(sl.isReadLocked());
        assertEquals(2, sl.getReadLockCount());
        lock.unlock();
        lock.unlock();
        assertUnlocked(sl);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:StampedLockTest.java

示例3: readerView

import java.util.concurrent.locks.StampedLock; //导入方法依赖的package包/类
static Reader readerView(final StampedLock sl, final Phaser gate) {
    return new Reader("ReaderView") { public void run() {
        if (gate != null ) toTheStartingGate(gate);
        final Lock rl = sl.asReadLock();
        rl.lock();
        try {
            stamp(1L);   // got the lock
            check(sl.isReadLocked());
            check(!sl.isWriteLocked());
        } finally { rl.unlock(); } }};
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:12,代码来源:Basic.java

示例4: testAsReadLock

import java.util.concurrent.locks.StampedLock; //导入方法依赖的package包/类
/**
 * asReadLock can be locked and unlocked
 */
public void testAsReadLock() {
    StampedLock sl = new StampedLock();
    Lock lock = sl.asReadLock();
    lock.lock();
    lock.unlock();
    assertTrue(lock.tryLock());
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:11,代码来源:StampedLockTest.java


注:本文中的java.util.concurrent.locks.StampedLock.asReadLock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。