本文整理了Java中java.util.concurrent.locks.ReentrantReadWriteLock.getWriteHoldCount
方法的一些代码示例,展示了ReentrantReadWriteLock.getWriteHoldCount
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ReentrantReadWriteLock.getWriteHoldCount
方法的具体详情如下:
包路径:java.util.concurrent.locks.ReentrantReadWriteLock
类名称:ReentrantReadWriteLock
方法名:getWriteHoldCount
[英]Queries the number of reentrant write holds on this lock by the current thread. A writer thread has a hold on a lock for each lock action that is not matched by an unlock action.
[中]查询当前线程在此锁上的可重入写入保留数。writer线程对每个锁操作都有一个保持锁,该锁操作与解锁操作不匹配。
代码示例来源:origin: Alluxio/alluxio
/**
* Queries the number of reentrant write holds on this lock by the current thread. A writer thread
* has a hold on a lock for each lock action that is not matched by an unlock action.
*
* @return the number of holds on the write lock by the current thread, or zero if the write lock
* is not held by the current thread
*/
public int getWriteHoldCount() {
return mDelegate.getWriteHoldCount();
}
代码示例来源:origin: Alluxio/alluxio
@VisibleForTesting
boolean inodeWriteLockedByCurrentThread(long inodeId) {
return mInodeLocks.getRawReadWriteLock(inodeId).getWriteHoldCount() > 0;
}
代码示例来源:origin: Alluxio/alluxio
@VisibleForTesting
boolean edgeWriteLockedByCurrentThread(Edge edge) {
return mEdgeLocks.getRawReadWriteLock(edge).getWriteHoldCount() > 0;
}
代码示例来源:origin: yahoo/squidb
/**
* Acquires an exclusive lock on the database. This is semantically similar to acquiring a write lock in a {@link
* java.util.concurrent.locks.ReadWriteLock ReadWriteLock} but it is not generally necessary for protecting actual
* database writes--it's only necessary when exclusive use of the database connection is required (e.g. while the
* database is attached to another database).
* <p>
* Only one thread can hold an exclusive lock at a time. Calling this while on a thread that already holds a non-
* exclusive lock is an error! We will throw an exception if this method is called while the
* calling thread is in a transaction or otherwise holds the non-exclusive lock. Otherwise, this method will block
* until all non-exclusive locks acquired with {@link #acquireNonExclusiveLock()} have been released, but will
* prevent any new non-exclusive locks from being acquired while it blocks.
*/
protected void acquireExclusiveLock() {
if (readWriteLock.getReadHoldCount() > 0 && readWriteLock.getWriteHoldCount() == 0) {
throw new IllegalStateException("Can't acquire an exclusive lock when the calling thread is in a "
+ "transaction or otherwise holds a non-exclusive lock and not the exclusive lock");
}
readWriteLock.writeLock().lock();
}
代码示例来源:origin: org.apache.hadoop/hadoop-hdfs
public int getWriteHoldCount() {
return coarseLock.getWriteHoldCount();
}
代码示例来源:origin: org.apache.hadoop/hadoop-hdfs
public int getWriteHoldCount() {
return this.dirLock.getWriteHoldCount();
}
代码示例来源:origin: apache/kylin
@Test
public void testBasics() {
AutoReadWriteLock lock = new AutoReadWriteLock(new ReentrantReadWriteLock());
try (AutoLock al = lock.lockForRead()) {
Assert.assertTrue(lock.innerLock().getReadHoldCount() == 1);
}
Assert.assertTrue(lock.innerLock().getReadHoldCount() == 0);
try (AutoLock al = lock.lockForWrite()) {
Assert.assertTrue(lock.innerLock().getWriteHoldCount() == 1);
}
Assert.assertTrue(lock.innerLock().getWriteHoldCount() == 0);
}
}
代码示例来源:origin: org.apache.hadoop/hadoop-hdfs
public void writeLock() {
coarseLock.writeLock().lock();
if (coarseLock.getWriteHoldCount() == 1) {
writeLockHeldTimeStampNanos = timer.monotonicNowNanos();
}
}
代码示例来源:origin: org.apache.hadoop/hadoop-hdfs
public void writeLockInterruptibly() throws InterruptedException {
coarseLock.writeLock().lockInterruptibly();
if (coarseLock.getWriteHoldCount() == 1) {
writeLockHeldTimeStampNanos = timer.monotonicNowNanos();
}
}
代码示例来源:origin: org.apache.hadoop/hadoop-hdfs
.getWriteHoldCount() == 1 && coarseLock.isWriteLockedByCurrentThread();
final long currentTimeNanos = timer.monotonicNowNanos();
final long writeLockIntervalNanos =
代码示例来源:origin: org.eclipse.xtext/org.eclipse.xtext.util
/**
* Queries the number of reentrant write holds on this lock by the current thread. Delegates to
* {@link ReentrantReadWriteLock#getWriteHoldCount()}.
*
* @return the number of holds on the write lock by the current thread, or zero if the write lock is not held by the
* current thread
* @since 2.4
* @noreference
*/
protected int getWriteHoldCount() {
return rwLock.getWriteHoldCount();
}
代码示例来源:origin: org.eclipse.xtext/util
/**
* Queries the number of reentrant write holds on this lock by the current thread. Delegates to
* {@link ReentrantReadWriteLock#getWriteHoldCount()}.
*
* @return the number of holds on the write lock by the current thread, or zero if the write lock is not held by the
* current thread
* @since 2.4
* @noreference
*/
protected int getWriteHoldCount() {
return rwLock.getWriteHoldCount();
}
代码示例来源:origin: org.apache.felix/org.apache.felix.scr
final void releaseActivationWriteeLock()
{
if (m_activationLock.getWriteHoldCount() > 0)
{
m_activationLock.writeLock().unlock();
}
}
代码示例来源:origin: apache/felix
final void releaseActivationWriteeLock()
{
if (m_activationLock.getWriteHoldCount() > 0)
{
m_activationLock.writeLock().unlock();
}
}
代码示例来源:origin: org.apache.felix/org.apache.felix.ipojo
/**
* Releases the write lock only and only if the write lock is held by the current thread.
* @return {@literal true} if the lock has no more holders, {@literal false} otherwise.
*/
public boolean releaseWriteLockIfHeld() {
if (m_lock.isWriteLockedByCurrentThread()) {
m_lock.writeLock().unlock();
}
return m_lock.getWriteHoldCount() == 0;
}
代码示例来源:origin: apache/felix
/**
* Releases the write lock only and only if the write lock is held by the current thread.
* @return {@literal true} if the lock has no more holders, {@literal false} otherwise.
*/
public boolean releaseWriteLockIfHeld() {
if (m_lock.isWriteLockedByCurrentThread()) {
m_lock.writeLock().unlock();
}
return m_lock.getWriteHoldCount() == 0;
}
代码示例来源:origin: io.prestosql.hadoop/hadoop-apache
public void writeLock() {
coarseLock.writeLock().lock();
if (coarseLock.getWriteHoldCount() == 1) {
writeLockHeldTimeStampNanos = timer.monotonicNowNanos();
}
}
代码示例来源:origin: org.glassfish.main.common/glassfish-api
public void dumpState(Logger logger, Level level) {
if (logger.isLoggable(level)) {
logger.log(level, "Current locking conditions are " + rwlock.getReadLockCount()
+ "/"+ rwlock.getReadHoldCount() + " shared locks"
+ "and " + rwlock.getWriteHoldCount() + " write lock");
}
}
代码示例来源:origin: io.prestosql.hadoop/hadoop-apache
public void writeLockInterruptibly() throws InterruptedException {
coarseLock.writeLock().lockInterruptibly();
if (coarseLock.getWriteHoldCount() == 1) {
writeLockHeldTimeStampNanos = timer.monotonicNowNanos();
}
}
代码示例来源:origin: apache/jena
private static void checkLock(ReentrantReadWriteLock rwx, int expectedR, int expectedW) {
int r = rwx.getReadHoldCount() ;
int w = rwx.getWriteHoldCount() ;
Assert.assertEquals("R", expectedR, r);
Assert.assertEquals("W", expectedW, w);
}
内容来源于网络,如有侵权,请联系作者删除!