當前位置: 首頁>>代碼示例>>Java>>正文


Java BlockingQueue.remainingCapacity方法代碼示例

本文整理匯總了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));
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:ArrayBlockingQueueTest.java

示例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;
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:14,代碼來源:FairCallQueue.java

示例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;
}
 
開發者ID:salesforce,項目名稱:storm-dynamic-spout,代碼行數:16,代碼來源:ThrottledMessageBuffer.java

示例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;
}
 
開發者ID:salesforce,項目名稱:storm-dynamic-spout,代碼行數:16,代碼來源:ThrottledMessageBuffer.java

示例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();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:10,代碼來源:JSR166TestCase.java


注:本文中的java.util.concurrent.BlockingQueue.remainingCapacity方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。