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


Java StampedLock.unlockWrite方法代码示例

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


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

示例1: interruptibleWriter

import java.util.concurrent.locks.StampedLock; //导入方法依赖的package包/类
static Writer interruptibleWriter(final StampedLock sl,
                                  final long timeout,
                                  final TimeUnit unit,
                                  final Phaser gate) {
    return new Writer("InterruptibleWriter") { public void run() {
        if (gate != null ) toTheStartingGate(gate);
        try {
            if (timeout < 0)
                stamp(sl.writeLockInterruptibly());
            else
                stamp(sl.tryWriteLock(timeout, unit));
            check(sl.validate(stamp()));
            check(!sl.isReadLocked());
            check(sl.isWriteLocked());
        } catch (Throwable x) { thrown(x);
        } finally { if (stamp() != 0L) sl.unlockWrite(stamp()); } }};
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:Basic.java

示例2: testLock

import java.util.concurrent.locks.StampedLock; //导入方法依赖的package包/类
/**
 * write-locking and read-locking an unlocked lock succeed
 */
public void testLock() {
    StampedLock lock = new StampedLock();
    assertFalse(lock.isWriteLocked());
    assertFalse(lock.isReadLocked());
    assertEquals(lock.getReadLockCount(), 0);
    long s = lock.writeLock();
    assertTrue(lock.isWriteLocked());
    assertFalse(lock.isReadLocked());
    assertEquals(lock.getReadLockCount(), 0);
    lock.unlockWrite(s);
    assertFalse(lock.isWriteLocked());
    assertFalse(lock.isReadLocked());
    assertEquals(lock.getReadLockCount(), 0);
    long rs = lock.readLock();
    assertFalse(lock.isWriteLocked());
    assertTrue(lock.isReadLocked());
    assertEquals(lock.getReadLockCount(), 1);
    lock.unlockRead(rs);
    assertFalse(lock.isWriteLocked());
    assertFalse(lock.isReadLocked());
    assertEquals(lock.getReadLockCount(), 0);
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:26,代码来源:StampedLockTest.java

示例3: testValidate

import java.util.concurrent.locks.StampedLock; //导入方法依赖的package包/类
/**
 * A stamp obtained from a successful lock operation validates
 */
public void testValidate() throws InterruptedException {
    StampedLock lock = new StampedLock();
    long s = lock.writeLock();
    assertTrue(lock.validate(s));
    lock.unlockWrite(s);
    s = lock.readLock();
    assertTrue(lock.validate(s));
    lock.unlockRead(s);
    assertTrue((s = lock.tryWriteLock()) != 0L);
    assertTrue(lock.validate(s));
    lock.unlockWrite(s);
    assertTrue((s = lock.tryReadLock()) != 0L);
    assertTrue(lock.validate(s));
    lock.unlockRead(s);
    assertTrue((s = lock.tryWriteLock(100L, MILLISECONDS)) != 0L);
    assertTrue(lock.validate(s));
    lock.unlockWrite(s);
    assertTrue((s = lock.tryReadLock(100L, MILLISECONDS)) != 0L);
    assertTrue(lock.validate(s));
    lock.unlockRead(s);
    assertTrue((s = lock.tryOptimisticRead()) != 0L);
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:26,代码来源:StampedLockTest.java

示例4: testReadTryLock_Timeout

import java.util.concurrent.locks.StampedLock; //导入方法依赖的package包/类
/**
 * timed tryReadLock times out if write-locked
 */
public void testReadTryLock_Timeout() {
    final StampedLock lock = new StampedLock();
    long s = lock.writeLock();
    Thread t = newStartedThread(new CheckedRunnable() {
        public void realRun() throws InterruptedException {
            long startTime = System.nanoTime();
            long timeoutMillis = 10;
            long rs = lock.tryReadLock(timeoutMillis, MILLISECONDS);
            assertEquals(rs, 0L);
            assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
        }});

    awaitTermination(t);
    assertTrue(lock.isWriteLocked());
    lock.unlockWrite(s);
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:20,代码来源:StampedLockTest.java

示例5: writer

import java.util.concurrent.locks.StampedLock; //导入方法依赖的package包/类
static Writer writer(final StampedLock sl, final Phaser gate) {
    return new Writer() { public void run() {
        if (gate != null ) toTheStartingGate(gate);
        try {
            stamp(sl.writeLock());
            check(sl.validate(stamp()));
            check(!sl.isReadLocked());
            check(sl.isWriteLocked());
        } finally { sl.unlockWrite(stamp()); } }};
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:Basic.java

示例6: releaseWriteLock

import java.util.concurrent.locks.StampedLock; //导入方法依赖的package包/类
/**
 * Releases write lock, checking isWriteLocked before and after
 */
void releaseWriteLock(StampedLock lock, long stamp) {
    assertTrue(lock.isWriteLocked());
    assertValid(lock, stamp);
    lock.unlockWrite(stamp);
    assertFalse(lock.isWriteLocked());
    assertFalse(lock.validate(stamp));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:StampedLockTest.java

示例7: testValidate2

import java.util.concurrent.locks.StampedLock; //导入方法依赖的package包/类
/**
 * A stamp obtained from an unsuccessful lock operation does not validate
 */
public void testValidate2() throws InterruptedException {
    StampedLock lock = new StampedLock();
    long s = assertNonZero(lock.writeLock());
    assertTrue(lock.validate(s));
    assertFalse(lock.validate(lock.tryWriteLock()));
    assertFalse(lock.validate(lock.tryWriteLock(randomExpiredTimeout(),
                                                randomTimeUnit())));
    assertFalse(lock.validate(lock.tryReadLock()));
    assertFalse(lock.validate(lock.tryWriteLock(randomExpiredTimeout(),
                                                randomTimeUnit())));
    assertFalse(lock.validate(lock.tryOptimisticRead()));
    lock.unlockWrite(s);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:StampedLockTest.java

示例8: testSerialization

import java.util.concurrent.locks.StampedLock; //导入方法依赖的package包/类
/**
 * A serialized lock deserializes as unlocked
 */
public void testSerialization() {
    StampedLock lock = new StampedLock();
    lock.writeLock();
    StampedLock clone = serialClone(lock);
    assertTrue(lock.isWriteLocked());
    assertFalse(clone.isWriteLocked());
    long s = clone.writeLock();
    assertTrue(clone.isWriteLocked());
    clone.unlockWrite(s);
    assertFalse(clone.isWriteLocked());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:StampedLockTest.java

示例9: testToString

import java.util.concurrent.locks.StampedLock; //导入方法依赖的package包/类
/**
 * toString indicates current lock state
 */
public void testToString() {
    StampedLock lock = new StampedLock();
    assertTrue(lock.toString().contains("Unlocked"));
    long s = lock.writeLock();
    assertTrue(lock.toString().contains("Write-locked"));
    lock.unlockWrite(s);
    s = lock.readLock();
    assertTrue(lock.toString().contains("Read-locks"));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:StampedLockTest.java

示例10: testValidateOptimisticWriteLocked

import java.util.concurrent.locks.StampedLock; //导入方法依赖的package包/类
/**
 * tryOptimisticRead stamp does not validate if a write lock intervenes
 */
public void testValidateOptimisticWriteLocked() {
    final StampedLock lock = new StampedLock();
    final long p = assertValid(lock, lock.tryOptimisticRead());
    final long s = assertValid(lock, lock.writeLock());
    assertFalse(lock.validate(p));
    assertEquals(0L, lock.tryOptimisticRead());
    assertTrue(lock.validate(s));
    lock.unlockWrite(s);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:StampedLockTest.java

示例11: testWriteUnlock_IMSE

import java.util.concurrent.locks.StampedLock; //导入方法依赖的package包/类
/**
 * write-unlocking an unlocked lock throws IllegalMonitorStateException
 */
public void testWriteUnlock_IMSE() {
    StampedLock lock = new StampedLock();
    try {
        lock.unlockWrite(0L);
        shouldThrow();
    } catch (IllegalMonitorStateException success) {}
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:11,代码来源:StampedLockTest.java

示例12: testWriteUnlock_IMSE2

import java.util.concurrent.locks.StampedLock; //导入方法依赖的package包/类
/**
 * write-unlocking an unlocked lock throws IllegalMonitorStateException
 */
public void testWriteUnlock_IMSE2() {
    StampedLock lock = new StampedLock();
    long s = lock.writeLock();
    lock.unlockWrite(s);
    try {
        lock.unlockWrite(s);
        shouldThrow();
    } catch (IllegalMonitorStateException success) {}
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:13,代码来源:StampedLockTest.java

示例13: testWriteUnlock_IMSE3

import java.util.concurrent.locks.StampedLock; //导入方法依赖的package包/类
/**
 * write-unlocking after readlock throws IllegalMonitorStateException
 */
public void testWriteUnlock_IMSE3() {
    StampedLock lock = new StampedLock();
    long s = lock.readLock();
    try {
        lock.unlockWrite(s);
        shouldThrow();
    } catch (IllegalMonitorStateException success) {}
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:12,代码来源:StampedLockTest.java

示例14: testValidate2

import java.util.concurrent.locks.StampedLock; //导入方法依赖的package包/类
/**
 * A stamp obtained from an unsuccessful lock operation does not validate
 */
public void testValidate2() throws InterruptedException {
    StampedLock lock = new StampedLock();
    long s;
    assertTrue((s = lock.writeLock()) != 0L);
    assertTrue(lock.validate(s));
    assertFalse(lock.validate(lock.tryWriteLock()));
    assertFalse(lock.validate(lock.tryWriteLock(10L, MILLISECONDS)));
    assertFalse(lock.validate(lock.tryReadLock()));
    assertFalse(lock.validate(lock.tryReadLock(10L, MILLISECONDS)));
    assertFalse(lock.validate(lock.tryOptimisticRead()));
    lock.unlockWrite(s);
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:16,代码来源:StampedLockTest.java

示例15: testValidateOptimistic

import java.util.concurrent.locks.StampedLock; //导入方法依赖的package包/类
/**
 * tryOptimisticRead succeeds and validates if unlocked, fails if locked
 */
public void testValidateOptimistic() throws InterruptedException {
    StampedLock lock = new StampedLock();
    long s, p;
    assertTrue((p = lock.tryOptimisticRead()) != 0L);
    assertTrue(lock.validate(p));
    assertTrue((s = lock.writeLock()) != 0L);
    assertFalse((p = lock.tryOptimisticRead()) != 0L);
    assertTrue(lock.validate(s));
    lock.unlockWrite(s);
    assertTrue((p = lock.tryOptimisticRead()) != 0L);
    assertTrue(lock.validate(p));
    assertTrue((s = lock.readLock()) != 0L);
    assertTrue(lock.validate(s));
    assertTrue((p = lock.tryOptimisticRead()) != 0L);
    assertTrue(lock.validate(p));
    lock.unlockRead(s);
    assertTrue((s = lock.tryWriteLock()) != 0L);
    assertTrue(lock.validate(s));
    assertFalse((p = lock.tryOptimisticRead()) != 0L);
    lock.unlockWrite(s);
    assertTrue((s = lock.tryReadLock()) != 0L);
    assertTrue(lock.validate(s));
    assertTrue((p = lock.tryOptimisticRead()) != 0L);
    lock.unlockRead(s);
    assertTrue(lock.validate(p));
    assertTrue((s = lock.tryWriteLock(100L, MILLISECONDS)) != 0L);
    assertFalse((p = lock.tryOptimisticRead()) != 0L);
    assertTrue(lock.validate(s));
    lock.unlockWrite(s);
    assertTrue((s = lock.tryReadLock(100L, MILLISECONDS)) != 0L);
    assertTrue(lock.validate(s));
    assertTrue((p = lock.tryOptimisticRead()) != 0L);
    lock.unlockRead(s);
    assertTrue((p = lock.tryOptimisticRead()) != 0L);
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:39,代码来源:StampedLockTest.java


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