本文整理了Java中java.util.concurrent.Semaphore.availablePermits()
方法的一些代码示例,展示了Semaphore.availablePermits()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Semaphore.availablePermits()
方法的具体详情如下:
包路径:java.util.concurrent.Semaphore
类名称:Semaphore
方法名:availablePermits
[英]Returns the current number of permits available in this semaphore.
This method is typically used for debugging and testing purposes.
[中]返回此信号量中当前可用的许可证数。
此方法通常用于调试和测试目的。
代码示例来源:origin: resilience4j/resilience4j
/**
* {@inheritDoc}
*/
@Override
public int getAvailablePermissions() {
return semaphore.availablePermits();
}
代码示例来源:origin: resilience4j/resilience4j
@Override
public int getAvailableConcurrentCalls() {
return semaphore.availablePermits();
}
}
代码示例来源:origin: twitter/distributedlog
@Override
public Number getSample() {
return null == semaphore ? 0 : concurrency - semaphore.availablePermits();
}
});
代码示例来源:origin: wildfly/wildfly
@Override
public int getBalance() {
return semaphore.availablePermits();
}
代码示例来源:origin: apache/geode
@Override
public String toString() {
return "<InitialImageFlowControl for GII to " + target + " with " + permits.availablePermits()
+ " available permits>";
}
代码示例来源:origin: org.apache.hadoop/hadoop-common
/**
* Size returns the sum of all sub-queue sizes, so it may be greater than
* capacity.
* Note: size provides no strict consistency, and should not be used to
* control queue IO.
*/
@Override
public int size() {
return semaphore.availablePermits();
}
代码示例来源:origin: voldemort/voldemort
public int availablePermits() {
return this.scanPermits.availablePermits();
}
代码示例来源:origin: org.apache.hadoop/hadoop-common
/**
* Get the number of permits available; guaranteed to be
* {@code 0 <= availablePermits <= size}.
* @return the number of permits available at the time of invocation.
*/
public int getAvailablePermits() {
return queueingPermits.availablePermits();
}
代码示例来源:origin: wildfly/wildfly
public int getAvailableCount() {
return semaphore.availablePermits();
}
代码示例来源:origin: Netflix/eureka
@Monitor(name = METRIC_REPLICATION_PREFIX + "pendingJobRequests", description = "Number of worker threads awaiting job assignment", type = DataSourceType.GAUGE)
public long getPendingJobRequests() {
return singleItemWorkRequests.availablePermits() + batchWorkRequests.availablePermits();
}
代码示例来源:origin: apache/hive
LockHandleImpl(Connection conn, Statement stmt, ResultSet rs, String key, Semaphore derbySemaphore) {
this.dbConn = conn;
this.stmt = stmt;
this.rs = rs;
this.derbySemaphore = derbySemaphore;
if(derbySemaphore != null) {
//oterwise it may later release permit acquired by someone else
assert derbySemaphore.availablePermits() == 0 : "Expected locked Semaphore";
}
keys.add(key);
}
void addKey(String key) {
代码示例来源:origin: pentaho/pentaho-kettle
@Override public synchronized void resume() {
if ( paused.getAndSet( false ) ) {
assert acceptingRowsSemaphore.availablePermits() == 0;
acceptingRowsSemaphore.release();
}
}
代码示例来源:origin: apache/flink
@VisibleForTesting
int getAvailablePermits() {
return semaphore.availablePermits();
}
代码示例来源:origin: resilience4j/resilience4j
void refreshLimit() {
int permissionsToRelease = this.rateLimiterConfig.get().getLimitForPeriod() - semaphore.availablePermits();
semaphore.release(permissionsToRelease);
}
代码示例来源:origin: apache/incubator-pinot
private void checkStopResourceManager() {
if (!isRunning && runningQueriesSemaphore.availablePermits() == numRunners) {
resourceManager.stop();
}
}
}
代码示例来源:origin: apache/geode
private void abort() {
if (!aborted.getAndSet(true)) {
incMessagesInFlight(-(maxPermits - permits.availablePermits()));
// Just in case java has issues with semaphores rolling over, set this
// to half Integer.MAX_VALUE rather to release all of the waiters
permits.release(Integer.MAX_VALUE / 2);
}
}
代码示例来源:origin: apache/flink
@VisibleForTesting
int getAcquiredPermits() {
return config.getMaxConcurrentRequests() - semaphore.availablePermits();
}
}
代码示例来源:origin: pentaho/pentaho-kettle
/**
* Marks the source paused (if not already) and acquires the permit, which will cause acceptRows to block.
*/
@Override public synchronized void pause() {
if ( !paused.getAndSet( true ) ) {
try {
assert acceptingRowsSemaphore.availablePermits() == 1;
acceptingRowsSemaphore.acquire();
} catch ( InterruptedException e ) {
logChannel.logError( getString( PKG, "BlockingQueueStream.PauseInterrupt" ) );
}
}
}
代码示例来源:origin: pentaho/pentaho-kettle
@Test
@SuppressWarnings ( "unchecked" )
public void errorLoggedIfInterruptedInPause() throws InterruptedException {
streamSource.acceptingRowsSemaphore = semaphore;
when( semaphore.availablePermits() ).thenReturn( 1 );
streamSource.logChannel = logChannel;
doThrow( new InterruptedException( "interrupt" ) )
.when( semaphore ).acquire();
streamSource.pause();
verify( logChannel ).logError( any() );
}
代码示例来源:origin: AsyncHttpClient/async-http-client
/**
* {@inheritDoc}
*/
@Override
public <T> FilterContext<T> filter(FilterContext<T> ctx) throws FilterException {
try {
if (logger.isDebugEnabled()) {
logger.debug("Current Throttling Status {}", available.availablePermits());
}
long startOfWait = System.currentTimeMillis();
attemptConcurrencyPermitAcquistion(ctx);
attemptRateLimitedPermitAcquistion(ctx, startOfWait);
} catch (InterruptedException e) {
throw new FilterException(String.format("Interrupted Request %s with AsyncHandler %s", ctx.getRequest(), ctx.getAsyncHandler()));
}
return new FilterContext.FilterContextBuilder<>(ctx)
.asyncHandler(ReleasePermitOnComplete.wrap(ctx.getAsyncHandler(), available))
.build();
}
内容来源于网络,如有侵权,请联系作者删除!