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

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

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

ReentrantReadWriteLock.<init>介绍

[英]Creates a new ReentrantReadWriteLock with default (nonfair) ordering properties.
[中]使用默认(非空)排序属性创建新的可重入TreadWriteLock。

代码示例

代码示例来源:origin: ReactiveX/RxJava

/**
 * Constructs an empty BehaviorSubject.
 * @since 2.0
 */
@SuppressWarnings("unchecked")
BehaviorSubject() {
  this.lock = new ReentrantReadWriteLock();
  this.readLock = lock.readLock();
  this.writeLock = lock.writeLock();
  this.subscribers = new AtomicReference<BehaviorDisposable<T>[]>(EMPTY);
  this.value = new AtomicReference<Object>();
  this.terminalEvent = new AtomicReference<Throwable>();
}

代码示例来源:origin: apache/hbase

public FileArchiverNotifierImpl(
  Connection conn, Configuration conf, FileSystem fs, TableName tn) {
 this.conn = conn;
 this.conf = conf;
 this.fs = fs;
 this.tn = tn;
 ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
 readLock = lock.readLock();
 writeLock = lock.writeLock();
}

代码示例来源:origin: apache/hive

private ReentrantReadWriteLock getDagLock(QueryIdentifier queryIdentifier) {
 lock.lock();
 try {
  ReentrantReadWriteLock dagLock = dagSpecificLocks.get(queryIdentifier);
  if (dagLock == null) {
   dagLock = new ReentrantReadWriteLock();
   dagSpecificLocks.put(queryIdentifier, dagLock);
  }
  return dagLock;
 } finally {
  lock.unlock();
 }
}

代码示例来源:origin: stackoverflow.com

import java.util.*;
import java.util.concurrent.locks.*;

public class UpgradeTest {

  public static void main(String[] args) 
  {   
    System.out.println("read to write test");
    ReadWriteLock lock = new ReentrantReadWriteLock();

    lock.readLock().lock(); // get our own read lock
    lock.writeLock().lock(); // upgrade to write lock
    System.out.println("passed");
  }

}

代码示例来源:origin: spotbugs/spotbugs

int foo() {
  ReadWriteLock myLock = new ReentrantReadWriteLock();
  myLock.writeLock().lock();
  int a = 6;
  int b = 9;
  int wrongAnswer = a * b;
  int rightAnswer = 42;
  myLock.writeLock().unlock();
  return wrongAnswer + rightAnswer;
}

代码示例来源:origin: stackoverflow.com

public final class MyCustomAppenderImpl extends AbstractAppender {
  private final ReadWriteLock rwLock = new ReentrantReadWriteLock();
  private final Lock readLock = rwLock.readLock();
    readLock.lock();
    try {
      final byte[] bytes = getLayout().toByteArray(event);

代码示例来源:origin: stackoverflow.com

class MyData {
  private final ReentrantReadWriteLock rwl = new ReentrantReadWriteLock();
  private final Lock r = rwl.readLock();
  private final Lock w = rwl.writeLock();

  public Data ReadSomething(int id) {
    r.lock();
    try {
      Cursor c = readableDatabase.query(...);
      return c.getString(0);
    } finally {
      r.unlock();
    }
  }

  public void ChangeSomething(int id, int value) {
    w.lock();
    try {
      writeableDatabase.update(...);
    } finally {
      w.unlock();
    }
  }
}

代码示例来源:origin: stackoverflow.com

// For example, here is a class using a TreeMap that is expected to be 
// large and concurrently accessed.
class RWDictionary {
  private final Map<String, Data> m = new TreeMap<String, Data>();
  private final ReentrantReadWriteLock rwl = new ReentrantReadWriteLock();
  private final Lock w = rwl.writeLock();

  // other code left out for brevity

  public void clear() {
    w.lock();  // write lock
    try { m.clear(); } // clear the TreeMap
    finally { w.unlock(); }
  }
}

代码示例来源:origin: apache/ignite

/**
 *
 */
@Test
public void testNotOwnedLockRelease() {
  ReadWriteLock lock = new ReentrantReadWriteLock();
  lock.readLock().unlock();
}

代码示例来源:origin: stackoverflow.com

ReentrantReadWriteLock.WriteLock lock = new ReentrantReadWriteLock(FAIR).writeLock();

代码示例来源:origin: stackoverflow.com

class Store
{
  private ReadWriteLock rwlock = new ReentrantReadWriteLock();

  public void write()
  {
    rwlock.writeLock().lock();
    try {
     write to store;
    } finally {
     rwlock.writeLock().unlock();
    }
  }

  public String read()
  {
    rwlock.readLock().lock();
    try {
     read from store;
    } finally {
     rwlock.readLock().unlock();
    }
  }
}

代码示例来源:origin: ReactiveX/RxJava

/**
 * Constructs an empty BehaviorProcessor.
 * @since 2.0
 */
@SuppressWarnings("unchecked")
BehaviorProcessor() {
  this.value = new AtomicReference<Object>();
  this.lock = new ReentrantReadWriteLock();
  this.readLock = lock.readLock();
  this.writeLock = lock.writeLock();
  this.subscribers = new AtomicReference<BehaviorSubscription<T>[]>(EMPTY);
  this.terminalEvent = new AtomicReference<Throwable>();
}

代码示例来源:origin: apache/incubator-pinot

public RealtimeInvertedIndexReader() {
 ReentrantReadWriteLock readWriteLock = new ReentrantReadWriteLock();
 _readLock = readWriteLock.readLock();
 _writeLock = readWriteLock.writeLock();
}

代码示例来源:origin: languagetool-org/languagetool

@Ignore("too slow to run every time")
@Test
public void testSpellCheckerFailure() throws Exception {
 String sampleText = createSampleText();
 Language language = createLanguage();
 int threadCount = Runtime.getRuntime().availableProcessors() * 10;
 int testRuns = 100;
 ReadWriteLock testWaitLock = new ReentrantReadWriteLock();
 Lock testWriteLock = testWaitLock.writeLock();
 testWriteLock.lock();
 
 failedTests = 0;
 
 List<Thread> threads = new ArrayList<>();
 for (int i = 0; i < threadCount; i++) {
  Thread t = new Thread(new TestRunner(testWaitLock, language, testRuns, sampleText));
  t.start();
  threads.add(t);
 }
 
 // Release the lock and allow all TestRunner threads to do their work.
 testWriteLock.unlock();
 
 for (Thread t : threads) {
  t.join();
 }
 
 Assert.assertEquals(0, failedTests);
}

代码示例来源:origin: apache/ignite

@Test
public void testTryWriteLock() throws Exception {
  final ReadWriteLock lock = new ReentrantReadWriteLock();
  lock.readLock().lock();
  lock.readLock().unlock();

代码示例来源:origin: stackoverflow.com

private final ReentrantReadWriteLock rwl = new ReentrantReadWriteLock();
private final Lock r = rwl.readLock();
private final Lock w = rwl.writeLock();
  r.lock();
  try {
    c = getReadableDatabase().query(...);
  w.lock();
  try {
    getWritableDatabase().update(...);
    @Override
    public void onBegin() {
      w.lock();

代码示例来源:origin: org.apache.james/apache-james-mailbox-store

@Override
protected void lock(MailboxSession session, MailboxPath path, boolean writeLock) throws MailboxException {
  ReadWriteLock lock = paths.get(path);
  if (lock == null) {
    lock = new ReentrantReadWriteLock();
    ReadWriteLock storedLock = paths.putIfAbsent(path, lock);
    if (storedLock != null) {
      lock = storedLock;
    }
  }
  getLock(lock, writeLock).lock();
}

代码示例来源:origin: apache/geode

@Override
protected void setInternalRegionArguments(InternalRegionArguments ira) {
 // PR specific
 PartitionedRegion pr = mock(PartitionedRegion.class);
 BucketAdvisor ba = mock(BucketAdvisor.class);
 ReadWriteLock primaryMoveLock = new ReentrantReadWriteLock();
 Lock primaryMoveReadLock = primaryMoveLock.readLock();
 when(ba.getPrimaryMoveReadLock()).thenReturn(primaryMoveReadLock);
 when(ba.getProxyBucketRegion()).thenReturn(mock(ProxyBucketRegion.class));
 when(ba.isPrimary()).thenReturn(true);
 ira.setPartitionedRegion(pr).setPartitionedRegionBucketRedundancy(1).setBucketAdvisor(ba);
}

代码示例来源:origin: apache/ignite

/**
 * @throws Exception If failed.
 */
@SuppressWarnings({"LockAcquiredButNotSafelyReleased"})
@Test
public void testReadThenWriteLockAcquire() throws Exception {
  ReadWriteLock lock = new ReentrantReadWriteLock();
  lock.readLock().lock();
  lock.writeLock().lock();
}

代码示例来源:origin: square/dagger

public Memoizer() {
 this.map = new LinkedHashMap<K, V>();
 ReadWriteLock lock = new ReentrantReadWriteLock();
 this.readLock = lock.readLock();
 this.writeLock = lock.writeLock();
}

相关文章