Example usage for java.util.concurrent.locks ReentrantReadWriteLock ReentrantReadWriteLock

List of usage examples for java.util.concurrent.locks ReentrantReadWriteLock ReentrantReadWriteLock

Introduction

In this page you can find the example usage for java.util.concurrent.locks ReentrantReadWriteLock ReentrantReadWriteLock.

Prototype

public ReentrantReadWriteLock() 

Source Link

Document

Creates a new ReentrantReadWriteLock with default (nonfair) ordering properties.

Usage

From source file:Main.java

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");
}

From source file:Main.java

private static ReentrantReadWriteLock getLock(String path) {
    ReentrantReadWriteLock lock = (ReentrantReadWriteLock) fileLocks.get(path);
    if (lock == null) {
        lock = new ReentrantReadWriteLock();
        ReentrantReadWriteLock oldLock = (ReentrantReadWriteLock) fileLocks.putIfAbsent(path, lock);
        if (oldLock != null) {
            lock = oldLock;/* w ww. j ava  2s.c  o m*/
        }
    }

    return lock;
}

From source file:org.mule.transformer.graph.GraphTransformerResolver.java

public GraphTransformerResolver() {
    this.readWriteLock = new ReentrantReadWriteLock();
    this.graph = new TransformationGraph();
    lookupStrategyTransformation = new TransformationGraphLookupStrategy(graph);
    converterFilter = new CompositeConverterFilter(new TransformationLengthConverterFilter(),
            new PriorityWeightingConverterFilter(), new NameConverterFilter());
    cache = new LRUMap();
}

From source file:RWStripedHashSet.java

/**
 * Constructor//  ww  w. j  a va  2  s.  c o  m
 * @param capacity Initial number of  buckets.
 */
public RWStripedHashSet(int capacity) {
    super(capacity);
    locks = new Lock[capacity];
    for (int j = 0; j < locks.length; j++) {
        locks[j] = new ReentrantLock();
    }
    ReadWriteLock rwLock = new ReentrantReadWriteLock();
    readLock = rwLock.readLock();
    writeLock = rwLock.writeLock();
}

From source file:org.yccheok.jstock.file.ThreadSafeFileLock.java

/***************************************************************************
 * CRITICAL SECTION OF THE CODE.//from  w  w w. jav a  2 s .c  o m
 **************************************************************************/
public static Lock getLock(File file) {
    String canonicalPath;
    try {
        canonicalPath = file.getCanonicalPath();
    } catch (IOException ex) {
        log.error(null, ex);
        return null;
    }

    Lock lock;
    synchronized (reentrantReadWriteLockMapMonitor) {
        lock = reentrantReadWriteLockMap.get(canonicalPath);
        if (lock == null) {
            ReentrantReadWriteLock reentrantReadWriteLock = new ReentrantReadWriteLock();
            AtomicInteger atomicInteger = new AtomicInteger(1);
            Pair<ReentrantReadWriteLock, AtomicInteger> pair = Pair.create(reentrantReadWriteLock,
                    atomicInteger);
            lock = new Lock(pair, canonicalPath);
            reentrantReadWriteLockMap.put(canonicalPath, lock);
        } else {
            lock.reentrantReadWriteLock.second.incrementAndGet();
        }
    }

    return lock;
}

From source file:com.amazonaws.internal.FIFOCache.java

/**
 * @param maxSize/*from   ww w . j ava2 s  .  c o m*/
 *            the maximum number of entries of the cache
 */
public FIFOCache(final int maxSize) {
    if (maxSize < 1) {
        throw new IllegalArgumentException("maxSize " + maxSize + " must be at least 1");
    }
    map = new BoundedLinkedHashMap<String, T>(maxSize);
    ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
    rlock = lock.readLock();
    wlock = lock.writeLock();
}

From source file:com.espertech.esper.filter.FilterParamIndexBooleanExpr.java

/**
 * Constructs the index for multiple-exact matches.
 *///from ww w  .j  a  va  2 s  .  c o m
public FilterParamIndexBooleanExpr() {
    super(FilterOperator.BOOLEAN_EXPRESSION);

    evaluatorsMap = new LinkedHashMap<ExprNodeAdapterBase, EventEvaluator>();
    constantsMapRWLock = new ReentrantReadWriteLock();
}

From source file:org.jactr.core.module.declarative.search.map.DefaultValueMap.java

public DefaultValueMap() {
    _lock = new ReentrantReadWriteLock();
    _map = instantiateCoreMap();
}

From source file:org.apache.hadoop.yarn.server.resourcemanager.placement.PlacementManager.java

public PlacementManager() {
    ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
    readLock = lock.readLock();
    writeLock = lock.writeLock();
}

From source file:com.espertech.esper.filter.FilterParamIndexStringRangeBase.java

protected FilterParamIndexStringRangeBase(FilterSpecLookupable lookupable, FilterOperator filterOperator) {
    super(filterOperator, lookupable);

    ranges = new TreeMap<StringRange, EventEvaluator>(new StringRangeComparator());
    rangesNullEndpoints = new IdentityHashMap<StringRange, EventEvaluator>();
    rangesRWLock = new ReentrantReadWriteLock();
}