java.util.concurrent.locks.ReentrantReadWriteLock.isFair()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(1.6k)|赞(0)|评价(0)|浏览(133)

本文整理了Java中java.util.concurrent.locks.ReentrantReadWriteLock.isFair方法的一些代码示例,展示了ReentrantReadWriteLock.isFair的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ReentrantReadWriteLock.isFair方法的具体详情如下:
包路径:java.util.concurrent.locks.ReentrantReadWriteLock
类名称:ReentrantReadWriteLock
方法名:isFair

ReentrantReadWriteLock.isFair介绍

[英]Returns true if this lock has fairness set true.
[中]如果此锁的公平性设置为true,则返回true。

代码示例

代码示例来源:origin: org.jgrapht/jgrapht-core

/**
 * Return whether fair mode is used for synchronizing access to this graph.
 * 
 * @return <tt>true</tt> if the graph uses fair mode, <tt>false</tt> if non-fair mode
 */
public boolean isFair()
{
  return readWriteLock.isFair();
}

代码示例来源:origin: vgrazi/java-concurrent-animated

public ReadWriteLockTester() {
 boolean fair;
 rwlock = new ReentrantReadWriteLock(fair = true);
 try {
  System.out.println("ReadWriteLockTester.ReadWriteLockTester fair:" + rwlock.isFair());
  readLock();
  writeLock();
  readLock();
  writeLock();
  readLock();
  writeLock();
  if (true) {
   Thread.sleep(3000);
   wakeRead();
   wakeRead();
   wakeRead();
   Thread.sleep(3000);
   System.exit(1);
  }
 } catch (InterruptedException e) {
  Thread.currentThread().interrupt();
 }
}

代码示例来源:origin: ch.cern.hadoop/hadoop-hdfs

@Test
public void testFsLockFairness() throws IOException, InterruptedException{
 Configuration conf = new Configuration();
 conf.setBoolean(DFS_NAMENODE_FSLOCK_FAIR_KEY, true);
 FSNamesystemLock fsnLock = new FSNamesystemLock(conf, null);
 assertTrue(fsnLock.coarseLock.isFair());
 conf.setBoolean(DFS_NAMENODE_FSLOCK_FAIR_KEY, false);
 fsnLock = new FSNamesystemLock(conf, null);
 assertFalse(fsnLock.coarseLock.isFair());
}

相关文章