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


Java ArrayBlockingQueue.remove方法代码示例

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


在下文中一共展示了ArrayBlockingQueue.remove方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: populatedQueue

import java.util.concurrent.ArrayBlockingQueue; //导入方法依赖的package包/类
/**
 * Returns a new queue of given size containing consecutive
 * Integers 0 ... n - 1, with given capacity range and fairness.
 */
static ArrayBlockingQueue<Integer> populatedQueue(
    int size, int minCapacity, int maxCapacity, boolean fair) {
    ThreadLocalRandom rnd = ThreadLocalRandom.current();
    int capacity = rnd.nextInt(minCapacity, maxCapacity + 1);
    ArrayBlockingQueue<Integer> q = new ArrayBlockingQueue<>(capacity);
    assertTrue(q.isEmpty());
    // shuffle circular array elements so they wrap
    {
        int n = rnd.nextInt(capacity);
        for (int i = 0; i < n; i++) q.add(42);
        for (int i = 0; i < n; i++) q.remove();
    }
    for (int i = 0; i < size; i++)
        assertTrue(q.offer((Integer) i));
    assertEquals(size == 0, q.isEmpty());
    assertEquals(capacity - size, q.remainingCapacity());
    assertEquals(size, q.size());
    if (size > 0)
        assertEquals((Integer) 0, q.peek());
    return q;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:ArrayBlockingQueueTest.java

示例3: testRetainAll

import java.util.concurrent.ArrayBlockingQueue; //导入方法依赖的package包/类
/**
 * retainAll(c) retains only those elements of c and reports true if changed
 */
public void testRetainAll() {
    ArrayBlockingQueue q = populatedQueue(SIZE);
    ArrayBlockingQueue p = populatedQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        boolean changed = q.retainAll(p);
        if (i == 0)
            assertFalse(changed);
        else
            assertTrue(changed);

        assertTrue(q.containsAll(p));
        assertEquals(SIZE - i, q.size());
        p.remove();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:ArrayBlockingQueueTest.java

示例4: remove

import java.util.concurrent.ArrayBlockingQueue; //导入方法依赖的package包/类
public String remove() {
    try {
        ArrayBlockingQueue arrayBlockingQueue = this.b0414ДД0414ДД;
        int i = bХ0425ХХ04250425;
        switch ((i * (b04250425ХХ04250425 + i)) % b0425ХХ042504250425()) {
            case 0:
                break;
            default:
                bХ0425ХХ04250425 = b0425Х0425Х04250425();
                bХ04250425Х04250425 = 94;
                break;
        }
        String str = (String) arrayBlockingQueue.remove();
        while (true) {
            switch (1) {
                case null:
                    break;
                case 1:
                    return str;
                default:
                    while (true) {
                        switch (1) {
                            case null:
                                break;
                            case 1:
                                return str;
                            default:
                        }
                    }
            }
        }
    } catch (NoSuchElementException e) {
        return null;
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:36,代码来源:ccrcrc.java

示例5: testRemove

import java.util.concurrent.ArrayBlockingQueue; //导入方法依赖的package包/类
/**
 * remove removes next element, or throws NSEE if empty
 */
public void testRemove() {
    ArrayBlockingQueue q = populatedQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.remove());
    }
    try {
        q.remove();
        shouldThrow();
    } catch (NoSuchElementException success) {}
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:ArrayBlockingQueueTest.java

示例6: testRemoveAll

import java.util.concurrent.ArrayBlockingQueue; //导入方法依赖的package包/类
/**
 * removeAll(c) removes only those elements of c and reports true if changed
 */
public void testRemoveAll() {
    for (int i = 1; i < SIZE; ++i) {
        ArrayBlockingQueue q = populatedQueue(SIZE);
        ArrayBlockingQueue p = populatedQueue(i);
        assertTrue(q.removeAll(p));
        assertEquals(SIZE - i, q.size());
        for (int j = 0; j < i; ++j) {
            Integer x = (Integer)(p.remove());
            assertFalse(q.contains(x));
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:ArrayBlockingQueueTest.java

示例7: testWeaklyConsistentIteration

import java.util.concurrent.ArrayBlockingQueue; //导入方法依赖的package包/类
/**
 * Modifications do not cause iterators to fail
 */
public void testWeaklyConsistentIteration() {
    final ArrayBlockingQueue q = new ArrayBlockingQueue(3);
    q.add(one);
    q.add(two);
    q.add(three);
    for (Iterator it = q.iterator(); it.hasNext();) {
        q.remove();
        it.next();
    }
    assertEquals(0, q.size());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:ArrayBlockingQueueTest.java

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