本文整理汇总了Java中java.util.concurrent.locks.StampedLock.asWriteLock方法的典型用法代码示例。如果您正苦于以下问题:Java StampedLock.asWriteLock方法的具体用法?Java StampedLock.asWriteLock怎么用?Java StampedLock.asWriteLock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.locks.StampedLock
的用法示例。
在下文中一共展示了StampedLock.asWriteLock方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: interruptibleWriterView
import java.util.concurrent.locks.StampedLock; //导入方法依赖的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(); } }};
}
示例2: writerView
import java.util.concurrent.locks.StampedLock; //导入方法依赖的package包/类
static Writer writerView(final StampedLock sl, final Phaser gate) {
return new Writer("WriterView") { public void run() {
if (gate != null ) toTheStartingGate(gate);
Lock wl = sl.asWriteLock();
wl.lock();
try {
stamp(1L); // got the lock
check(!sl.isReadLocked());
check(sl.isWriteLocked());
} finally { wl.unlock(); } }};
}
示例3: testAsWriteLock
import java.util.concurrent.locks.StampedLock; //导入方法依赖的package包/类
/**
* asWriteLock can be locked and unlocked
*/
public void testAsWriteLock() throws Throwable {
StampedLock sl = new StampedLock();
Lock lock = sl.asWriteLock();
for (Action locker : lockLockers(lock)) {
locker.run();
assertTrue(sl.isWriteLocked());
assertFalse(sl.isReadLocked());
assertFalse(lock.tryLock());
lock.unlock();
assertUnlocked(sl);
}
}
示例4: testAsWriteLock
import java.util.concurrent.locks.StampedLock; //导入方法依赖的package包/类
/**
* asWriteLock can be locked and unlocked
*/
public void testAsWriteLock() {
StampedLock sl = new StampedLock();
Lock lock = sl.asWriteLock();
lock.lock();
assertFalse(lock.tryLock());
lock.unlock();
assertTrue(lock.tryLock());
}