public ConcurrentLWJGLBufferAllocator() { this.stampedLock = new StampedLock(); }
public ConcurrentEvictingQueue(int capacity) { if (capacity <= 0) { throw new IllegalArgumentException(ILLEGAL_CAPACITY); } maxSize = capacity; ringBuffer = new Object[capacity]; size = 0; headIndex = 0; tailIndex = 0; modificationsCount = 0; stampedLock = new StampedLock(); }
protected ForkedProcessorStep( StageControl control, String name, Configuration config, StatsProvider... statsProviders ) { super( control, name, config, statsProviders ); this.maxProcessors = config.maxNumberOfProcessors(); this.forkedProcessors = new Object[this.maxProcessors]; stripingLock = new StampedLock(); Unit noop = new Unit( -1, null, 0 ); head = new AtomicReference<>( noop ); tail = new AtomicReference<>( noop ); stripingLock.unlock( applyProcessorCount( stripingLock.readLock() ) ); downstreamSender = new CompletedBatchesSender( name + " [CompletedBatchSender]" ); maxQueueLength = 200 + maxProcessors; }
public static void main(String[] args) { ExecutorService executor = Executors.newFixedThreadPool(2); StampedLock lock = new StampedLock(); executor.submit(() -> { long stamp = lock.readLock(); try { if (count == 0) { stamp = lock.tryConvertToWriteLock(stamp); if (stamp == 0L) { System.out.println("Could not convert to write lock"); stamp = lock.writeLock(); } count = 23; } System.out.println(count); } finally { lock.unlock(stamp); } }); ConcurrentUtils.stop(executor); }
public static void main(String[] args) { ExecutorService executor = Executors.newFixedThreadPool(2); Map<String, String> map = new HashMap<>(); StampedLock lock = new StampedLock(); executor.submit(() -> { long stamp = lock.writeLock(); try { ConcurrentUtils.sleep(1); map.put("foo", "bar"); } finally { lock.unlockWrite(stamp); } }); Runnable readTask = () -> { long stamp = lock.readLock(); try { System.out.println(map.get("foo")); ConcurrentUtils.sleep(1); } finally { lock.unlockRead(stamp); } }; executor.submit(readTask); executor.submit(readTask); ConcurrentUtils.stop(executor); }
public static void main(String[] args) { ExecutorService executor = Executors.newFixedThreadPool(2); StampedLock lock = new StampedLock(); executor.submit(() -> { long stamp = lock.tryOptimisticRead(); try { System.out.println("Optimistic Lock Valid: " + lock.validate(stamp)); ConcurrentUtils.sleep(1); System.out.println("Optimistic Lock Valid: " + lock.validate(stamp)); ConcurrentUtils.sleep(2); System.out.println("Optimistic Lock Valid: " + lock.validate(stamp)); } finally { lock.unlock(stamp); } }); executor.submit(() -> { long stamp = lock.writeLock(); try { System.out.println("Write Lock acquired"); ConcurrentUtils.sleep(2); } finally { lock.unlock(stamp); System.out.println("Write done"); } }); ConcurrentUtils.stop(executor); }
public RangeRouter(HashRouter<K> keyRouter) { this.keyRouter = keyRouter; this.lock = new StampedLock(); }
public ConcurrentLWJGLBufferAllocator() { this.stampedLock = new StampedLock(); }
private StampedLock makeLock() { return new StampedLock(); }
private StampedLock makeLock() { return new StampedLock(); }
/** * Creates a new instance of AbstractFutureActionContext with the supplied engine, action and * source bindings. * * @param engine * Parent engine. * @param action * The action this context is for. * @param sourceBindings * Bindings to shallow copy. */ protected AbstractFutureActionContext(final ActionEngine engine, final Action<T> action, final ActionBindings sourceBindings) { super(engine, action, sourceBindings); lock = new StampedLock(); future = null; }
public ConcurrentEvictingQueue(int capacity) { if (capacity <= 0) { throw new IllegalArgumentException(ILLEGAL_CAPACITY); } maxSize = capacity; ringBuffer = new Object[capacity]; size = 0; headIndex = 0; tailIndex = 0; modificationsCount = 0; stampedLock = new StampedLock(); }
/** * Construct a new instance. * * @param comparator */ @SuppressWarnings("unchecked") private IncrementalSortMap(Comparator<? super K> comparator) { this.sorted = comparator == null ? new ConcurrentSkipListMap<K, V>() : new ConcurrentSkipListMap<K, V>(comparator); this.segments = new HashMap[concurrencyLevel]; this.segmentLocks = new StampedLock[concurrencyLevel]; for (int i = 0; i < concurrencyLevel; i++) { segments[i] = Maps.<K, V> newHashMap(); segmentLocks[i] = new StampedLock(); } }
@SuppressWarnings( "unchecked" ) public StampedCopyOnWriteArrayList(Class<? extends T> clazz) { this.data = (T[]) newInstance( clazz, 0 ); lock = new StampedLock(); optimisticStamp = lock.tryOptimisticRead(); }
@Override public void lock(@Nonnull final DocumentReference document) { try { final Lock lock = this.locks.computeIfAbsent(document, k -> new StampedLock().asWriteLock()); final boolean cleanLock = lock.tryLock(10, TimeUnit.SECONDS); if (!cleanLock) { this.logger.debug("Timed out while waiting for lock on [{}], proceeding anyway", document); } } catch (InterruptedException ex) { // We don't expect any interruptions this.logger.error("Unexpected interruption while waiting for lock: {}", ex.getMessage(), ex); } }
ReadWriteLock lock = new StampedLock().asReadWriteLock();
/** * Default constructor */ public ScalableRWLock() { // States of the Readers, one entry in the list per thread readersStateList = new ConcurrentLinkedQueue<AtomicInteger>(); stampedLock = new StampedLock(); // Default value for "entry" is null which is ok because, the thread // calling the constructor may never attempt to read-lock this // instance and, therefore, there is not point in allocating an // instance of ReadersEntry for it. entry = new ThreadLocal<ReadersEntry>(); readersStateArrayRef = new AtomicReference<AtomicInteger[]>(null); readerLock = new ScalableRWLock.InnerReadLock(); writerLock = new ScalableRWLock.InnerWriteLock(); }
FileRefSource(ChannelMaster master) { super(master); this.references = PlatformDependent.newMpscQueue(); this.semaphore = new StampedLock(); // throw away a writeLock so that we can immediately park the consumer this.semaphore.writeLock(); this.shortCircuited = false; }
protected AbstractRegistrationTree() { final StampedLock lock = new StampedLock(); readLock = lock.asReadLock(); writeLock = lock.asWriteLock(); }
protected ForkedProcessorStep( StageControl control, String name, Configuration config, StatsProvider... statsProviders ) { super( control, name, config, statsProviders ); this.maxProcessors = config.maxNumberOfProcessors(); this.forkedProcessors = new Object[this.maxProcessors]; stripingLock = new StampedLock(); Unit noop = new Unit( -1, null, 0 ); head = new AtomicReference<>( noop ); tail = new AtomicReference<>( noop ); stripingLock.unlock( applyProcessorCount( stripingLock.readLock() ) ); downstreamSender = new CompletedBatchesSender( name + " [CompletedBatchSender]" ); maxQueueLength = 200 + maxProcessors; }