本文整理汇总了Java中java.util.concurrent.BlockingQueue.remainingCapacity方法的典型用法代码示例。如果您正苦于以下问题:Java BlockingQueue.remainingCapacity方法的具体用法?Java BlockingQueue.remainingCapacity怎么用?Java BlockingQueue.remainingCapacity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.BlockingQueue
的用法示例。
在下文中一共展示了BlockingQueue.remainingCapacity方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRemainingCapacity
import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
/**
* remainingCapacity decreases on add, increases on remove
*/
public void testRemainingCapacity() {
int size = ThreadLocalRandom.current().nextInt(1, SIZE);
BlockingQueue q = populatedQueue(size, size, 2 * size, false);
int spare = q.remainingCapacity();
int capacity = spare + size;
for (int i = 0; i < size; i++) {
assertEquals(spare + i, q.remainingCapacity());
assertEquals(capacity, q.size() + q.remainingCapacity());
assertEquals(i, q.remove());
}
for (int i = 0; i < size; i++) {
assertEquals(capacity - i, q.remainingCapacity());
assertEquals(capacity, q.size() + q.remainingCapacity());
assertTrue(q.add(i));
}
}
示例2: remainingCapacity
import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
/**
* Returns maximum remaining capacity. This does not reflect how much you can
* ideally fit in this FairCallQueue, as that would depend on the scheduler's
* decisions.
*/
@Override
public int remainingCapacity() {
int sum = 0;
for (BlockingQueue q : this.queues) {
sum += q.remainingCapacity();
}
return sum;
}
示例3: getThrottledVirtualSpoutIdentifiers
import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
/**
* Internal method used *ONLY* within tests. Hacky implementation -- could have race-conditions in other use-cases.
* @return Set of all VirtualSpoutIds that ARE throttled.
*/
Set<VirtualSpoutIdentifier> getThrottledVirtualSpoutIdentifiers() {
Set<VirtualSpoutIdentifier> throttledVirtualSpoutIds = new HashSet<>();
for (Map.Entry<VirtualSpoutIdentifier, BlockingQueue<Message>> entry: messageBuffer.entrySet()) {
BlockingQueue<Message> queue = entry.getValue();
if (queue.remainingCapacity() + queue.size() == getThrottledBufferSize()) {
throttledVirtualSpoutIds.add(entry.getKey());
}
}
return throttledVirtualSpoutIds;
}
示例4: getNonThrottledVirtualSpoutIdentifiers
import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
/**
* Internal method used *ONLY* within tests. Hacky implementation -- could have race-conditions in other use-cases.
* @return Set of all VirtualSpoutIds that are NOT throttled.
*/
Set<VirtualSpoutIdentifier> getNonThrottledVirtualSpoutIdentifiers() {
Set<VirtualSpoutIdentifier> nonThrottledVirtualSpoutIds = new HashSet<>();
for (Map.Entry<VirtualSpoutIdentifier, BlockingQueue<Message>> entry: messageBuffer.entrySet()) {
BlockingQueue<Message> queue = entry.getValue();
if (queue.remainingCapacity() + queue.size() > getThrottledBufferSize()) {
nonThrottledVirtualSpoutIds.add(entry.getKey());
}
}
return nonThrottledVirtualSpoutIds;
}
示例5: saturatedSize
import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
/**
* Returns maximum number of tasks that can be submitted to given
* pool (with bounded queue) before saturation (when submission
* throws RejectedExecutionException).
*/
static final int saturatedSize(ThreadPoolExecutor pool) {
BlockingQueue<Runnable> q = pool.getQueue();
return pool.getMaximumPoolSize() + q.size() + q.remainingCapacity();
}