/** * 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>(); }
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"); } }
/** * Before SDK 21, BitmapRegionDecoder was not synchronized internally. Any attempt to decode * regions from multiple threads with one decoder instance causes a segfault. For old versions * use the write lock to enforce single threaded decoding. */ private Lock getDecodeLock() { if (Build.VERSION.SDK_INT < 21) { return decoderLock.writeLock(); } else { return decoderLock.readLock(); } } }
public PipelineTimelineEntry instanceFor(CaseInsensitiveString pipelineName, int index) { scheduleOrderLock.readLock().lock(); try { ArrayList<PipelineTimelineEntry> instances = scheduleOrderPmm.get(pipelineName); return instances == null ? null : instances.get(index); } finally { scheduleOrderLock.readLock().unlock(); } }
/** * 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>(); }
/** * @throws Exception If failed. */ @SuppressWarnings({"LockAcquiredButNotSafelyReleased"}) @Test public void testReadThenWriteLockAcquire() throws Exception { ReadWriteLock lock = new ReentrantReadWriteLock(); lock.readLock().lock(); lock.writeLock().lock(); }
private boolean hasCriticalField(Class<?> clazz, String field) { // Lock the write lock criticalFieldsLock.readLock().lock(); try { Set<String> classesWithField = criticalFields.get(field); if (classesWithField == null) { return false; } if (!classesWithField.contains(clazz.getName())) { return false; } return true; } finally { criticalFieldsLock.readLock().unlock(); } }
/** * Returns the number of milli-seconds the currently executing job spent in the queue * waiting for an available executor. This excludes the quiet period time of the job. * @since 1.440 */ public long getTimeSpentInQueue() { lock.readLock().lock(); try { return startTime - workUnit.context.item.buildableStartMilliseconds; } finally { lock.readLock().unlock(); } }
public Memoizer() { this.map = new LinkedHashMap<K, V>(); ReadWriteLock lock = new ReentrantReadWriteLock(); this.readLock = lock.readLock(); this.writeLock = lock.writeLock(); }
DeprecatedNaturalIdCacheStatisticsImpl(String regionName, Set<NaturalIdDataAccess> accessStrategies) { this.regionName = regionName; this.accessStrategies = accessStrategies; final ReadWriteLock lock = new ReentrantReadWriteLock(); this.readLock = lock.readLock(); this.writeLock = lock.writeLock(); }
private Lock getLock(SingletonComponent lockableComponent, Method method) { LockType lockType = lockableComponent.getLockType(method); switch (lockType) { case READ: return lockableComponent.getLock().readLock(); case WRITE: return lockableComponent.getLock().writeLock(); } throw EjbLogger.ROOT_LOGGER.failToObtainLockIllegalType(lockType, method, lockableComponent); }