List of usage examples for java.util.concurrent.locks ReentrantLock ReentrantLock
public ReentrantLock()
From source file:StripedHashSet.java
public StripedHashSet(int capacity) { super(capacity); locks = new Lock[capacity]; for (int j = 0; j < locks.length; j++) { locks[j] = new ReentrantLock(); }/*from w w w . j ava2s. c o m*/ }
From source file:com.esofthead.mycollab.lock.DistributionLockUtil.java
@SuppressWarnings("unchecked") private static Lock getStaticDefaultLock(String lockName) { synchronized (map) { Lock lock = (Lock) map.get(lockName); if (lock == null) { lock = new ReentrantLock(); map.put(lockName, lock);/* w ww.ja v a 2 s . c om*/ } return lock; } }
From source file:LinkList.java
public LinkList(E value) { this.value = value; rest = null; lock = new ReentrantLock(); valueChanged = lock.newCondition(); linkChanged = lock.newCondition(); }
From source file:RefinableHashSet.java
/** * Concurrent Cuckoo hash set. Resizes lock array. * @param capacity Initial number of buckets. *//* www .j av a 2 s . co m*/ public RefinableHashSet(int capacity) { super(capacity); locks = new ReentrantLock[capacity]; for (int j = 0; j < capacity; j++) { locks[j] = new ReentrantLock(); } owner = new AtomicMarkableReference<Thread>(null, false); }
From source file:com.qut.middleware.esoemanager.util.PolicyIDGenerator.java
public PolicyIDGenerator() { this.lock = new ReentrantLock(); try {/*from w w w . j a v a 2 s .c o m*/ /* Attempt to get the specified RNG instance */ this.random = SecureRandom.getInstance(this.RNG); } catch (NoSuchAlgorithmException nsae) { this.logger.error(Messages.getString("IdentifierGeneratorImpl.13")); //$NON-NLS-1$ this.logger.debug(nsae.getLocalizedMessage(), nsae); this.random = new SecureRandom(); } this.random.setSeed(System.currentTimeMillis()); }
From source file:RWStripedHashSet.java
/** * Constructor/*from ww w.j a va 2s .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.codehaus.wadi.core.contextualiser.HashingCollapser.java
public HashingCollapser(int numSyncs, final long timeout) { locks = new Lock[numSyncs]; for (int i = 0; i < locks.length; i++) { locks[i] = new ReentrantLock() { public void lock() { try { tryLock(timeout, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { throw new WADIRuntimeException(e); }//ww w . j a va 2s . c om } public void lockInterruptibly() throws InterruptedException { boolean locked = tryLock(timeout, TimeUnit.MILLISECONDS); if (!locked) { throw new WADIRuntimeException("Cannot acquire lock after " + timeout + "ms"); } } public boolean tryLock() { try { return tryLock(timeout, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { throw new WADIRuntimeException(e); } } }; } }
From source file:info.pancancer.arch3.worker.CollectingLogOutputStream.java
/** * Process a line./*from ww w. j ava 2 s . c o m*/ * * @param line * - A line. * @param level * - a logging level. Not used in this implementation. */ @Override protected void processLine(String line, int level) { Lock lock = new ReentrantLock(); lock.lock(); lines.add(line); lock.unlock(); }
From source file:ome.services.blitz.util.ServantHolder.java
/** * Acquires the given lock or if necessary creates a new one. * //from ww w. j a v a2s . co m * @param key */ public void acquireLock(String key) { Lock lock = new ReentrantLock(); Lock oldLock = locks.putIfAbsent(key, lock); // If there was already a lock, // then the new lock can be gc'd if (oldLock != null) { lock = oldLock; } lock.lock(); }
From source file:org.fim.internal.hash.HashProgress.java
public HashProgress(Context context) { this.context = context; this.progressLock = new ReentrantLock(); }