@Override public void lock() { mAvailable.acquireUninterruptibly(mPermits); }
public void suspend() { acquisitionSemaphore.acquireUninterruptibly(MAX_PERMITS); }
public boolean acquire() { throttle.acquireUninterruptibly(); // Don't start new requests if there is an exception if (exceptions.size() > 0) { latch.decrementAndGet(); throttle.release(); return false; } return true; }
@Override public void execute(Runnable task) { semaphore.acquireUninterruptibly(); try { super.execute(task); } catch (Throwable t) { semaphore.release(); throw new RuntimeException(t); } }
public void lock() { semaphore.acquireUninterruptibly(); if (log.isDebugEnabled()) { owner = Thread.currentThread().getName(); position = Thread.currentThread().getStackTrace()[2].toString(); log.debug("<<< Lock {} acquired at {}", this.hashCode(), position); } }
/** * Acquire a decoder. Blocks until one is available. */ private BitmapRegionDecoder acquire() { available.acquireUninterruptibly(); return getNextAvailable(); }
@Override public void acquireUninterruptibly() { if (incHoldCount()) { super.acquireUninterruptibly(); } }
@Override public void acquireGIIPermitUninterruptibly() { this.parallelGIIs.acquireUninterruptibly(); this.stats.incInitialImageRequestsInProgress(1); }
public void acquire() throws SQLException { if (acquisitionSemaphore.tryAcquire()) { return; } else if (Boolean.getBoolean("com.zaxxer.hikari.throwIfSuspended")) { throw new SQLTransientException("The pool is currently suspended and configured to throw exceptions upon acquisition"); } acquisitionSemaphore.acquireUninterruptibly(); }
private void flush() { semaphore.acquireUninterruptibly(config.getMaxConcurrentRequests()); semaphore.release(config.getMaxConcurrentRequests()); }
@Override public void lock() { SessionState.get().getCompileLock().lock(); globalCompileQuotas.acquireUninterruptibly(); }
/** * {@inheritDoc} */ @Override public void changeConfig(final BulkheadConfig newConfig) { synchronized (configChangesLock) { int delta = newConfig.getMaxConcurrentCalls() - config.getMaxConcurrentCalls(); if (delta < 0) { semaphore.acquireUninterruptibly(-delta); } else if (delta > 0) { semaphore.release(delta); } config = newConfig; } }
public void enqueueUpdate( DatabaseIndex<? extends IndexReader> index, IndexUpdater indexUpdater, IndexEntryUpdate<?> update ) { updateQueueLimit.acquireUninterruptibly(); Runnable eventualUpdate = () -> { try { indexUpdater.process( update ); } catch ( IndexEntryConflictException e ) { markAsFailed( index, e ); } finally { updateQueueLimit.release(); } }; try { scheduler.schedule( Group.INDEX_UPDATING, eventualUpdate ); } catch ( Exception e ) { updateQueueLimit.release(); // Avoid leaking permits if job scheduling fails. throw e; } }
public void add( int delta ) { semaphore.acquireUninterruptibly(); sum.add( delta ); count.increment(); } }
public void lock(HoldType type) { while (true) { LockTransition transition = invoke(LockMessaging.lock(type)); if (transition.isAcquired()) { currentState = LockMessaging.lock(type); return; } else { wakeup.acquireUninterruptibly(); } } }
/** * Adds write future to the pending list and returns the size of the queue. * <p> * Note that separate counter for the queue size is needed because in case of concurrent * calls this method should return different values (when queue size is 0 and 2 concurrent calls * occur exactly one call will return 1) * * @param writeFut Write request to add. * @return Updated size of the queue. */ int offerFuture(SessionWriteRequest writeFut) { boolean msgThread = GridNioBackPressureControl.threadProcessingMessage(); if (sem != null && !msgThread) sem.acquireUninterruptibly(); writeFut.messageThread(msgThread); boolean res = queue.offer(writeFut); assert res : "Future was not added to queue"; return queue.sizex(); }
@Test public void mustNotStartRecurringTasksWherePriorExecutionHasNotYetFinished() { Runnable runnable = () -> { counter.incrementAndGet(); semaphore.acquireUninterruptibly(); }; scheduler.submit( Group.STORAGE_MAINTENANCE, runnable, 100, 100 ); for ( int i = 0; i < 4; i++ ) { scheduler.tick(); clock.forward( 100, TimeUnit.NANOSECONDS ); } semaphore.release( Integer.MAX_VALUE ); pools.getThreadPool( Group.STORAGE_MAINTENANCE ).shutDown(); assertThat( counter.get(), is( 1 ) ); }
semaphore.acquireUninterruptibly(); }; JobHandle handle = scheduler.submit( Group.STORAGE_MAINTENANCE, recurring, 100, 100 );
@Test public void testThreadPoolsUsingDefaultPool() throws Exception { Configuration configuration = new XmlConfiguration(this.getClass().getResource("/configs/thread-pools.xml")); final CacheManager cacheManager = CacheManagerBuilder.newCacheManager(configuration); cacheManager.init(); try { Cache<String, String> cache = cacheManager.createCache("testThreadPools", newCacheConfigurationBuilder(String.class, String.class, heap(10)) .add(new DefaultCacheLoaderWriterConfiguration(ThreadRememberingLoaderWriter.class)) .add(newUnBatchedWriteBehindConfiguration()) .build()); cache.put("foo", "bar"); ThreadRememberingLoaderWriter.USED.acquireUninterruptibly(); assertThat(ThreadRememberingLoaderWriter.LAST_SEEN_THREAD.getName(), containsString("[big]")); } finally { cacheManager.close(); } }
@Test public void testThreadPools() throws Exception { Configuration configuration = new XmlConfiguration(this.getClass().getResource("/configs/thread-pools.xml")); final CacheManager cacheManager = CacheManagerBuilder.newCacheManager(configuration); cacheManager.init(); try { Cache<String, String> cache = cacheManager.createCache("testThreadPools", newCacheConfigurationBuilder(String.class, String.class, heap(10)) .add(new DefaultCacheLoaderWriterConfiguration(ThreadRememberingLoaderWriter.class)) .add(newUnBatchedWriteBehindConfiguration().useThreadPool("small")) .build()); cache.put("foo", "bar"); ThreadRememberingLoaderWriter.USED.acquireUninterruptibly(); assertThat(ThreadRememberingLoaderWriter.LAST_SEEN_THREAD.getName(), containsString("[small]")); } finally { cacheManager.close(); } }