当前位置: 首页>>代码示例>>Java>>正文


Java ArrayBlockingQueue.remainingCapacity方法代码示例

本文整理汇总了Java中java.util.concurrent.ArrayBlockingQueue.remainingCapacity方法的典型用法代码示例。如果您正苦于以下问题:Java ArrayBlockingQueue.remainingCapacity方法的具体用法?Java ArrayBlockingQueue.remainingCapacity怎么用?Java ArrayBlockingQueue.remainingCapacity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.ArrayBlockingQueue的用法示例。


在下文中一共展示了ArrayBlockingQueue.remainingCapacity方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addToSendQueue

import java.util.concurrent.ArrayBlockingQueue; //导入方法依赖的package包/类
/**
 * Inserts an element in the specified queue. If the Queue is full, this
 * method removes an element from the head of the Queue and then inserts
 * the element at the tail. It can happen that the an element is removed
 * by another thread in {@link SendWorker#processMessage() processMessage}
 * method before this method attempts to remove an element from the queue.
 * This will cause {@link ArrayBlockingQueue#remove() remove} to throw an
 * exception, which is safe to ignore.
 *
 * Unlike {@link #addToRecvQueue(Message) addToRecvQueue} this method does
 * not need to be synchronized since there is only one thread that inserts
 * an element in the queue and another thread that reads from the queue.
 *
 * @param queue
 *          Reference to the Queue
 * @param buffer
 *          Reference to the buffer to be inserted in the queue
 */
private void addToSendQueue(ArrayBlockingQueue<ByteBuffer> queue,
      ByteBuffer buffer) {
    if (queue.remainingCapacity() == 0) {
        try {
            queue.remove();
        } catch (NoSuchElementException ne) {
            // element could be removed by poll()
            LOG.debug("Trying to remove from an empty " +
                    "Queue. Ignoring exception " + ne);
        }
    }
    try {
        queue.add(buffer);
    } catch (IllegalStateException ie) {
        // This should never happen
        LOG.error("Unable to insert an element in the queue " + ie);
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:37,代码来源:QuorumCnxManager.java

示例2: testClear

import java.util.concurrent.ArrayBlockingQueue; //导入方法依赖的package包/类
/**
 * clear removes all elements
 */
public void testClear() {
    int size = ThreadLocalRandom.current().nextInt(1, 5);
    ArrayBlockingQueue q = populatedQueue(size, size, 2 * size, false);
    int capacity = size + q.remainingCapacity();
    q.clear();
    assertTrue(q.isEmpty());
    assertEquals(0, q.size());
    assertEquals(capacity, q.remainingCapacity());
    q.add(one);
    assertFalse(q.isEmpty());
    assertTrue(q.contains(one));
    q.clear();
    assertTrue(q.isEmpty());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:ArrayBlockingQueueTest.java

示例3: randomizePutIndex

import java.util.concurrent.ArrayBlockingQueue; //导入方法依赖的package包/类
/**
 * Instead of having putIndex (and takeIndex) at the initial
 * default of 0, move them to a random location.
 */
void randomizePutIndex(ArrayBlockingQueue q) {
    assertTrue(q.isEmpty());
    int capacity = q.remainingCapacity();
    int n = rnd.nextInt(capacity + 1);
    int putIndex = putIndex(q);
    for (int i = n; i-->0; ) q.add(Boolean.TRUE);
    for (int i = n; i-->0; ) q.remove();
    assertEquals(putIndex(q), (putIndex + n) % items(q).length);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:WhiteBox.java


注:本文中的java.util.concurrent.ArrayBlockingQueue.remainingCapacity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。