类java.util.concurrent.ConcurrentLinkedDeque源码实例Demo

下面列出了怎么用java.util.concurrent.ConcurrentLinkedDeque的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: moleculer-java   文件: WrongOrderTransporter.java
public void run() {
	synchronized (channels) {
		for (Map.Entry<String, ConcurrentLinkedDeque<Tree>> entry : channels.entrySet()) {
			String channel = entry.getKey();
			if (!channel.startsWith(nodeID + ':')) {
				continue;
			}
			int i = channel.indexOf(':');
			channel = channel.substring(i + 1);
			ConcurrentLinkedDeque<Tree> queue = entry.getValue();
			while (!queue.isEmpty()) {
				Tree message = queue.removeLast();
				try {
					received(channel, serializer.write(message));
				} catch (Exception cause) {
					logger.error("Unable to serialize message!", cause);
				}
			}
		}
	}
}
 
源代码2 项目: quarkus-http   文件: JDBCLogHandler.java
public JDBCLogHandler(final HttpHandler next, final String formatString, DataSource dataSource) {
    this.next = next;
    this.formatString = formatString;
    this.dataSource = dataSource;

    tableName = "access";
    remoteHostField = "remoteHost";
    userField = "userName";
    timestampField = "timestamp";
    virtualHostField = "virtualHost";
    methodField = "method";
    queryField = "query";
    statusField = "status";
    bytesField = "bytes";
    refererField = "referer";
    userAgentField = "userAgent";
    this.pendingMessages = new ConcurrentLinkedDeque<>();
}
 
源代码3 项目: DDMQ   文件: BatchMQProducer.java
public void send(CarreraRequest request, MessageQueueSelector messageQueueSelector)
    throws RemotingException, MQClientException, InterruptedException, MQBrokerException {
    TopicPublishInfo topicInfo = clusterProducer.getRocketMQProducerByIndex(0).getDefaultMQProducerImpl().getTopicPublishInfoTable().get(request.getTopic());
    if (topicInfo == null || !topicInfo.ok()) { //new topic
        sendSingleMessage(request);
        return;
    }

    MessageQueue mq = messageQueueSelector.select(topicInfo.getMessageQueueList(), null, request);
    request.setMessageQueue(mq);

    requestQMap.computeIfAbsent(mq.getBrokerName(), _name -> {
        Deque<CarreraRequest> q = new ConcurrentLinkedDeque<>();
        addRequestQueue(q, _name, config.getMaxEncodeWorkerForEachBroker());
        return q;
    }).add(request);
}
 
源代码4 项目: jdk8u-dev-jdk   文件: RemovePollRace.java
Collection<Queue<Boolean>> concurrentQueues() {
    List<Queue<Boolean>> queues = new ArrayList<Queue<Boolean>>();
    queues.add(new ConcurrentLinkedDeque<Boolean>());
    queues.add(new ConcurrentLinkedQueue<Boolean>());
    queues.add(new ArrayBlockingQueue<Boolean>(count, false));
    queues.add(new ArrayBlockingQueue<Boolean>(count, true));
    queues.add(new LinkedBlockingQueue<Boolean>());
    queues.add(new LinkedBlockingDeque<Boolean>());
    queues.add(new LinkedTransferQueue<Boolean>());

    // Following additional implementations are available from:
    // http://gee.cs.oswego.edu/dl/concurrency-interest/index.html
    // queues.add(new SynchronizedLinkedListQueue<Boolean>());

    // Avoid "first fast, second slow" benchmark effect.
    Collections.shuffle(queues);
    return queues;
}
 
源代码5 项目: native-obfuscator   文件: RemovePollRace.java
Collection<Queue<Boolean>> concurrentQueues() {
    List<Queue<Boolean>> queues = new ArrayList<Queue<Boolean>>();
    queues.add(new ConcurrentLinkedDeque<Boolean>());
    queues.add(new ConcurrentLinkedQueue<Boolean>());
    queues.add(new ArrayBlockingQueue<Boolean>(count, false));
    queues.add(new ArrayBlockingQueue<Boolean>(count, true));
    queues.add(new LinkedBlockingQueue<Boolean>());
    queues.add(new LinkedBlockingDeque<Boolean>());
    queues.add(new LinkedTransferQueue<Boolean>());

    // Following additional implementations are available from:
    // http://gee.cs.oswego.edu/dl/concurrency-interest/index.html
    // queues.add(new SynchronizedLinkedListQueue<Boolean>());

    // Avoid "first fast, second slow" benchmark effect.
    Collections.shuffle(queues);
    return queues;
}
 
源代码6 项目: jdk8u60   文件: RemovePollRace.java
Collection<Queue<Boolean>> concurrentQueues() {
    List<Queue<Boolean>> queues = new ArrayList<Queue<Boolean>>();
    queues.add(new ConcurrentLinkedDeque<Boolean>());
    queues.add(new ConcurrentLinkedQueue<Boolean>());
    queues.add(new ArrayBlockingQueue<Boolean>(count, false));
    queues.add(new ArrayBlockingQueue<Boolean>(count, true));
    queues.add(new LinkedBlockingQueue<Boolean>());
    queues.add(new LinkedBlockingDeque<Boolean>());
    queues.add(new LinkedTransferQueue<Boolean>());

    // Following additional implementations are available from:
    // http://gee.cs.oswego.edu/dl/concurrency-interest/index.html
    // queues.add(new SynchronizedLinkedListQueue<Boolean>());

    // Avoid "first fast, second slow" benchmark effect.
    Collections.shuffle(queues);
    return queues;
}
 
源代码7 项目: openjdk-jdk9   文件: ConcurrentLinkedDequeTest.java
/**
 * iterator.remove() removes current element
 */
public void testIteratorRemove() {
    final ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
    final Random rng = new Random();
    for (int iters = 0; iters < 100; ++iters) {
        int max = rng.nextInt(5) + 2;
        int split = rng.nextInt(max - 1) + 1;
        for (int j = 1; j <= max; ++j)
            q.add(new Integer(j));
        Iterator it = q.iterator();
        for (int j = 1; j <= split; ++j)
            assertEquals(it.next(), new Integer(j));
        it.remove();
        assertEquals(it.next(), new Integer(split + 1));
        for (int j = 1; j <= split; ++j)
            q.remove(new Integer(j));
        it = q.iterator();
        for (int j = split + 1; j <= max; ++j) {
            assertEquals(it.next(), new Integer(j));
            it.remove();
        }
        assertFalse(it.hasNext());
        assertTrue(q.isEmpty());
    }
}
 
源代码8 项目: super-cloudops   文件: TimeoutsHealthIndicator.java
public void addTimes(String metricName, long time) {
	if (logger.isDebugEnabled()) {
		logger.debug("MetricName={}, time={}", metricName, time);
	}
	int latestCount = conf.getSamples();
	Deque<Long> deque = this.records.get(metricName);
	if (deque == null) {
		if (logger.isInfoEnabled()) {
			logger.info("Initial timeoutsHealthIndicator, metricName={}, capacity: {}", metricName, latestCount);
		}
		deque = new ConcurrentLinkedDeque<>();
	}
	// Overflow check.
	if (deque.size() >= (latestCount - 1)) {
		deque.poll(); // Remove first.
	}
	deque.offer(time);
	this.records.put(metricName, deque);
}
 
源代码9 项目: openjdk-jdk8u   文件: RemovePollRace.java
Collection<Queue<Boolean>> concurrentQueues() {
    List<Queue<Boolean>> queues = new ArrayList<Queue<Boolean>>();
    queues.add(new ConcurrentLinkedDeque<Boolean>());
    queues.add(new ConcurrentLinkedQueue<Boolean>());
    queues.add(new ArrayBlockingQueue<Boolean>(count, false));
    queues.add(new ArrayBlockingQueue<Boolean>(count, true));
    queues.add(new LinkedBlockingQueue<Boolean>());
    queues.add(new LinkedBlockingDeque<Boolean>());
    queues.add(new LinkedTransferQueue<Boolean>());

    // Following additional implementations are available from:
    // http://gee.cs.oswego.edu/dl/concurrency-interest/index.html
    // queues.add(new SynchronizedLinkedListQueue<Boolean>());

    // Avoid "first fast, second slow" benchmark effect.
    Collections.shuffle(queues);
    return queues;
}
 
源代码10 项目: jdk8u_jdk   文件: RemovePollRace.java
Collection<Queue<Boolean>> concurrentQueues() {
    List<Queue<Boolean>> queues = new ArrayList<Queue<Boolean>>();
    queues.add(new ConcurrentLinkedDeque<Boolean>());
    queues.add(new ConcurrentLinkedQueue<Boolean>());
    queues.add(new ArrayBlockingQueue<Boolean>(count, false));
    queues.add(new ArrayBlockingQueue<Boolean>(count, true));
    queues.add(new LinkedBlockingQueue<Boolean>());
    queues.add(new LinkedBlockingDeque<Boolean>());
    queues.add(new LinkedTransferQueue<Boolean>());

    // Following additional implementations are available from:
    // http://gee.cs.oswego.edu/dl/concurrency-interest/index.html
    // queues.add(new SynchronizedLinkedListQueue<Boolean>());

    // Avoid "first fast, second slow" benchmark effect.
    Collections.shuffle(queues);
    return queues;
}
 
源代码11 项目: openjdk-jdk9   文件: ConcurrentLinkedDequeTest.java
/**
 * descendingIterator.remove() removes current element
 */
public void testDescendingIteratorRemove() {
    final ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
    final Random rng = new Random();
    for (int iters = 0; iters < 100; ++iters) {
        int max = rng.nextInt(5) + 2;
        int split = rng.nextInt(max - 1) + 1;
        for (int j = max; j >= 1; --j)
            q.add(new Integer(j));
        Iterator it = q.descendingIterator();
        for (int j = 1; j <= split; ++j)
            assertEquals(it.next(), new Integer(j));
        it.remove();
        assertEquals(it.next(), new Integer(split + 1));
        for (int j = 1; j <= split; ++j)
            q.remove(new Integer(j));
        it = q.descendingIterator();
        for (int j = split + 1; j <= max; ++j) {
            assertEquals(it.next(), new Integer(j));
            it.remove();
        }
        assertFalse(it.hasNext());
        assertTrue(q.isEmpty());
    }
}
 
源代码12 项目: hottub   文件: RemovePollRace.java
Collection<Queue<Boolean>> concurrentQueues() {
    List<Queue<Boolean>> queues = new ArrayList<Queue<Boolean>>();
    queues.add(new ConcurrentLinkedDeque<Boolean>());
    queues.add(new ConcurrentLinkedQueue<Boolean>());
    queues.add(new ArrayBlockingQueue<Boolean>(count, false));
    queues.add(new ArrayBlockingQueue<Boolean>(count, true));
    queues.add(new LinkedBlockingQueue<Boolean>());
    queues.add(new LinkedBlockingDeque<Boolean>());
    queues.add(new LinkedTransferQueue<Boolean>());

    // Following additional implementations are available from:
    // http://gee.cs.oswego.edu/dl/concurrency-interest/index.html
    // queues.add(new SynchronizedLinkedListQueue<Boolean>());

    // Avoid "first fast, second slow" benchmark effect.
    Collections.shuffle(queues);
    return queues;
}
 
源代码13 项目: lams   文件: JDBCLogHandler.java
public JDBCLogHandler(final HttpHandler next, final String formatString, DataSource dataSource) {
    this.next = next;
    this.formatString = formatString;
    this.dataSource = dataSource;

    tableName = "access";
    remoteHostField = "remoteHost";
    userField = "userName";
    timestampField = "timestamp";
    virtualHostField = "virtualHost";
    methodField = "method";
    queryField = "query";
    statusField = "status";
    bytesField = "bytes";
    refererField = "referer";
    userAgentField = "userAgent";
    this.pendingMessages = new ConcurrentLinkedDeque<>();
}
 
源代码14 项目: openjdk-8   文件: RemovePollRace.java
Collection<Queue<Boolean>> concurrentQueues() {
    List<Queue<Boolean>> queues = new ArrayList<Queue<Boolean>>();
    queues.add(new ConcurrentLinkedDeque<Boolean>());
    queues.add(new ConcurrentLinkedQueue<Boolean>());
    queues.add(new ArrayBlockingQueue<Boolean>(count, false));
    queues.add(new ArrayBlockingQueue<Boolean>(count, true));
    queues.add(new LinkedBlockingQueue<Boolean>());
    queues.add(new LinkedBlockingDeque<Boolean>());
    queues.add(new LinkedTransferQueue<Boolean>());

    // Following additional implementations are available from:
    // http://gee.cs.oswego.edu/dl/concurrency-interest/index.html
    // queues.add(new SynchronizedLinkedListQueue<Boolean>());

    // Avoid "first fast, second slow" benchmark effect.
    Collections.shuffle(queues);
    return queues;
}
 
源代码15 项目: openjdk-jdk9   文件: RemovePollRace.java
Collection<Queue<Boolean>> concurrentQueues() {
    List<Queue<Boolean>> queues = new ArrayList<>();
    queues.add(new ConcurrentLinkedDeque<Boolean>());
    queues.add(new ConcurrentLinkedQueue<Boolean>());
    queues.add(new ArrayBlockingQueue<Boolean>(count, false));
    queues.add(new ArrayBlockingQueue<Boolean>(count, true));
    queues.add(new LinkedBlockingQueue<Boolean>());
    queues.add(new LinkedBlockingDeque<Boolean>());
    queues.add(new LinkedTransferQueue<Boolean>());

    // Following additional implementations are available from:
    // http://gee.cs.oswego.edu/dl/concurrency-interest/index.html
    // queues.add(new SynchronizedLinkedListQueue<Boolean>());

    // Avoid "first fast, second slow" benchmark effect.
    Collections.shuffle(queues);
    return queues;
}
 
源代码16 项目: j2objc   文件: ConcurrentLinkedDequeTest.java
/**
 * element() returns first element, or throws NSEE if empty
 */
public void testElement() {
    ConcurrentLinkedDeque q = populatedDeque(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.element());
        assertEquals(i, q.poll());
    }
    try {
        q.element();
        shouldThrow();
    } catch (NoSuchElementException success) {}
}
 
源代码17 项目: j2objc   文件: ConcurrentLinkedDequeTest.java
/**
 * offerFirst(x) succeeds
 */
public void testOfferFirst() {
    ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
    assertTrue(q.offerFirst(zero));
    assertTrue(q.offerFirst(one));
    assertSame(one, q.peekFirst());
    assertSame(zero, q.peekLast());
}
 
源代码18 项目: enode   文件: AggregateRoot.java
private void appendUncommittedEvent(IDomainEvent<TAggregateRootId> domainEvent) {
    if (uncommittedEvents == null) {
        uncommittedEvents = new ConcurrentLinkedDeque<>();
    }
    if (uncommittedEvents.stream().anyMatch(x -> x.getClass().equals(domainEvent.getClass()))) {
        throw new UnsupportedOperationException(String.format("Cannot apply duplicated domain event type: %s, current aggregateRoot type: %s, id: %s", domainEvent.getClass(), this.getClass().getName(), id));
    }
    uncommittedEvents.add(domainEvent);
}
 
源代码19 项目: openjdk-jdk9   文件: ConcurrentLinkedDequeTest.java
/**
 * poll() succeeds unless empty
 */
public void testPoll() {
    ConcurrentLinkedDeque q = populatedDeque(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.poll());
    }
    assertNull(q.poll());
}
 
源代码20 项目: openjdk-jdk9   文件: ConcurrentLinkedDequeTest.java
/**
 * isEmpty is true before add, false after
 */
public void testEmpty() {
    ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
    assertTrue(q.isEmpty());
    q.add(one);
    assertFalse(q.isEmpty());
    q.add(two);
    q.remove();
    q.remove();
    assertTrue(q.isEmpty());
}
 
源代码21 项目: j2objc   文件: ConcurrentLinkedDequeTest.java
/**
 * peekLast() returns next element, or null if empty
 */
public void testPeekLast() {
    ConcurrentLinkedDeque q = populatedDeque(SIZE);
    for (int i = SIZE - 1; i >= 0; --i) {
        assertEquals(i, q.peekLast());
        assertEquals(i, q.pollLast());
        assertTrue(q.peekLast() == null ||
                   !q.peekLast().equals(i));
    }
    assertNull(q.peekLast());
}
 
源代码22 项目: openjdk-jdk9   文件: ConcurrentLinkedDequeTest.java
/**
 * Initializing from Collection of null elements throws NPE
 */
public void testConstructor4() {
    try {
        new ConcurrentLinkedDeque(Arrays.asList(new Integer[SIZE]));
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
源代码23 项目: j2objc   文件: ConcurrentLinkedDequeTest.java
/**
 * offerLast(null) throws NPE
 */
public void testOfferLastNull() {
    ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
    try {
        q.offerLast(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
源代码24 项目: j2objc   文件: ConcurrentLinkedDequeTest.java
/**
 * poll() succeeds unless empty
 */
public void testPoll() {
    ConcurrentLinkedDeque q = populatedDeque(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.poll());
    }
    assertNull(q.poll());
}
 
源代码25 项目: j2objc   文件: ConcurrentLinkedDequeTest.java
/**
 * peekFirst() returns next element, or null if empty
 */
public void testPeekFirst() {
    ConcurrentLinkedDeque q = populatedDeque(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.peekFirst());
        assertEquals(i, q.pollFirst());
        assertTrue(q.peekFirst() == null ||
                   !q.peekFirst().equals(i));
    }
    assertNull(q.peekFirst());
}
 
源代码26 项目: aion   文件: NodeMgrTest.java
@Test
public void testConcurrentAccess() throws InterruptedException {
    Deque<INode> inbound = new ConcurrentLinkedDeque<>();
    Deque<INode> outbound = new ConcurrentLinkedDeque<>();

    List<Runnable> threads = new ArrayList<>();
    // due to the maximum number of threads used, active nodes will not be rejected here
    for (int i = 0; i < MAX_ACTIVE_NODES; i++) {
        threads.add(generateTempNode());
        threads.add(moveTempNodeToOutbound(outbound));
        threads.add(moveTempNodeToInbound(inbound));
        threads.add(movePeerToActive(inbound, outbound));
    }

    assertConcurrent("Testing concurrent use of NodeMgr with additions to temp, inbound, outbound and active.", threads, TIME_OUT);

    // print the resulting set of active peers
    System.out.println(nMgr.dumpNodeInfo("self", true));

    assertTrue(nMgr.activeNodesSize() <= MAX_ACTIVE_NODES);
    // the following assert can fail, but under normal circumstances the odds are extremely low
    // if it fails consistently there is very likely a bug in the node management
    assertTrue(nMgr.activeNodesSize() > 0);

    // also remove active nodes
    for (int i = 0; i < MAX_ACTIVE_NODES; i++) {
        threads.add(dropActive());
    }

    assertConcurrent("Testing concurrent use of NodeMgr use with added deletions.", threads, TIME_OUT);

    // print the resulting set of active peers
    System.out.println(nMgr.dumpNodeInfo("self", true));

    assertTrue(nMgr.activeNodesSize() <= MAX_ACTIVE_NODES);
    // the following assert can fail, but under normal circumstances the odds are extremely low
    // if it fails consistently there is very likely a bug in the node management
    assertTrue(nMgr.activeNodesSize() > 0);
}
 
源代码27 项目: FastAsyncWorldedit   文件: MappedFaweQueue.java
@Override
public void addEditSession(EditSession session) {
    ConcurrentLinkedDeque<EditSession> tmp = sessions;
    if (tmp == null) tmp = new ConcurrentLinkedDeque<>();
    tmp.add(session);
    this.sessions = tmp;
}
 
源代码28 项目: j2objc   文件: ConcurrentLinkedDequeTest.java
/**
 * pollLast() succeeds unless empty
 */
public void testPollLast() {
    ConcurrentLinkedDeque q = populatedDeque(SIZE);
    for (int i = SIZE - 1; i >= 0; --i) {
        assertEquals(i, q.pollLast());
    }
    assertNull(q.pollLast());
}
 
源代码29 项目: openjdk-jdk9   文件: ConcurrentLinkedDequeTest.java
/**
 * add(null) throws NPE
 */
public void testAddNull() {
    ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
    try {
        q.add(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
源代码30 项目: clust4j   文件: MeanShift.java
static ConcurrentSkipListSet<MeanShiftSeed> doAll(
		int maxIter, double[][] X, RadiusNeighbors nbrs,
		ConcurrentLinkedDeque<SummaryLite> summaries) {
	
	return getThreadPool().invoke(
		new ParallelSeedExecutor(
			maxIter, X, nbrs,
			summaries));
}
 
 类所在包
 同包方法