當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。