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


Java LinkedBlockingDeque类代码示例

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


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

示例1: AnomalyDetector

import java.util.concurrent.LinkedBlockingDeque; //导入依赖的package包/类
public AnomalyDetector(KafkaCruiseControlConfig config,
                       LoadMonitor loadMonitor,
                       KafkaCruiseControl kafkaCruiseControl,
                       Time time,
                       MetricRegistry dropwizardMetricRegistry) {
  _anomalies = new LinkedBlockingDeque<>();
  _anomalyDetectionIntervalMs = config.getLong(KafkaCruiseControlConfig.ANOMALY_DETECTION_INTERVAL_MS_CONFIG);
  _anomalyNotifier = config.getConfiguredInstance(KafkaCruiseControlConfig.ANOMALY_NOTIFIER_CLASS_CONFIG,
                                                  AnomalyNotifier.class);
  _goalViolationDetector = new GoalViolationDetector(config, loadMonitor, _anomalies, time);
  _brokerFailureDetector = new BrokerFailureDetector(config, loadMonitor, _anomalies, time);
  _kafkaCruiseControl = kafkaCruiseControl;
  _detectorScheduler =
      Executors.newScheduledThreadPool(3, new KafkaCruiseControlThreadFactory("AnomalyDetector", false, LOG));
  _shutdown = false;
  _brokerFailureRate = dropwizardMetricRegistry.meter(MetricRegistry.name("AnomalyDetector", "broker-failure-rate"));
  _goalViolationRate = dropwizardMetricRegistry.meter(MetricRegistry.name("AnomalyDetector", "goal-violation-rate"));

}
 
开发者ID:linkedin,项目名称:cruise-control,代码行数:20,代码来源:AnomalyDetector.java

示例2: calculateTxnProfileTotals

import java.util.concurrent.LinkedBlockingDeque; //导入依赖的package包/类
private void calculateTxnProfileTotals(Procedure catalog_proc, long totals[]) {
    long tuple[] = null;
    LinkedBlockingDeque<long[]> queue = this.txn_profile_queues.get(catalog_proc); 
    while ((tuple = queue.poll()) != null) {
        totals[0]++;
        for (int i = 0, cnt = tuple.length; i < cnt; i++) {
            totals[i+1] += tuple[i];
        } // FOR
    } // FOR
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:11,代码来源:HStoreSiteStatus.java

示例3: testDescendingIteratorOrdering

import java.util.concurrent.LinkedBlockingDeque; //导入依赖的package包/类
/**
 * Descending iterator ordering is reverse FIFO
 */
public void testDescendingIteratorOrdering() {
    final LinkedBlockingDeque q = new LinkedBlockingDeque();
    for (int iters = 0; iters < 100; ++iters) {
        q.add(new Integer(3));
        q.add(new Integer(2));
        q.add(new Integer(1));
        int k = 0;
        for (Iterator it = q.descendingIterator(); it.hasNext();) {
            assertEquals(++k, it.next());
        }

        assertEquals(3, k);
        q.remove();
        q.remove();
        q.remove();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:LinkedBlockingDequeTest.java

示例4: main

import java.util.concurrent.LinkedBlockingDeque; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
     final int maxPairs = (args.length > 0)
         ? Integer.parseInt(args[0])
         : 5;
     int iters = 10000;

     pool = Executors.newCachedThreadPool();
     for (int i = 1; i <= maxPairs; i += (i+1) >>> 1) {
         // Adjust iterations to limit typical single runs to <= 10 ms;
         // Notably, fair queues get fewer iters.
         // Unbounded queues can legitimately OOME if iterations
         // high enough, but we have a sufficiently low limit here.
         run(new ArrayBlockingQueue<Integer>(100), i, 500);
         run(new LinkedBlockingQueue<Integer>(100), i, 1000);
         run(new LinkedBlockingDeque<Integer>(100), i, 1000);
         run(new LinkedTransferQueue<Integer>(), i, 1000);
         run(new PriorityBlockingQueue<Integer>(), i, 1000);
         run(new SynchronousQueue<Integer>(), i, 400);
         run(new SynchronousQueue<Integer>(true), i, 300);
         run(new ArrayBlockingQueue<Integer>(100, true), i, 100);
     }
     pool.shutdown();
     if (! pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS))
         throw new Error();
     pool = null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:ProducerConsumerLoops.java

示例5: testDescendingIteratorRemove

import java.util.concurrent.LinkedBlockingDeque; //导入依赖的package包/类
/**
 * descendingIterator.remove removes current element
 */
public void testDescendingIteratorRemove() {
    final LinkedBlockingDeque q = new LinkedBlockingDeque();
    for (int iters = 0; iters < 100; ++iters) {
        q.add(new Integer(3));
        q.add(new Integer(2));
        q.add(new Integer(1));
        Iterator it = q.descendingIterator();
        assertEquals(it.next(), new Integer(1));
        it.remove();
        assertEquals(it.next(), new Integer(2));
        it = q.descendingIterator();
        assertEquals(it.next(), new Integer(2));
        assertEquals(it.next(), new Integer(3));
        it.remove();
        assertFalse(it.hasNext());
        q.remove();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:LinkedBlockingDequeTest.java

示例6: putAllCollections

import java.util.concurrent.LinkedBlockingDeque; //导入依赖的package包/类
static void putAllCollections(Map<Class<?>, IntFunction<?>> map, Map<Class<?>, Function<?, ?>> unmodMap)
{
    safePut(map, ArrayList.class, ArrayList::new);
    safePut(map, HashSet.class, LinkedHashSet::new);
    safePut(map, Properties.class, x -> new Properties());
    safePut(map, Hashtable.class, Hashtable::new);

    safePut(map, Collection.class, ArrayList::new);
    safePut(map, Set.class, LinkedHashSet::new);
    safePut(map, List.class, ArrayList::new);
    safePut(map, SortedSet.class, x -> new TreeSet<>());
    safePut(map, Queue.class, x -> new ConcurrentLinkedQueue<>());
    safePut(map, Deque.class, x -> new ConcurrentLinkedDeque<>());
    safePut(map, BlockingQueue.class, x -> new LinkedBlockingQueue<>());
    safePut(map, BlockingDeque.class, x -> new LinkedBlockingDeque<>());


    safePut(map, HashMap.class, LinkedHashMap::new);
    safePut(map, LinkedHashMap.class, LinkedHashMap::new);
    safePut(map, ConcurrentHashMap.class, ConcurrentHashMap::new);

    safePut(map, Map.class, LinkedHashMap::new);
    safePut(map, ConcurrentMap.class, x -> new ConcurrentSkipListMap<>());
    safePut(map, ConcurrentNavigableMap.class, x -> new ConcurrentSkipListMap<>());
    safePut(map, SortedMap.class, i -> new TreeMap<>());
}
 
开发者ID:GotoFinal,项目名称:diorite-configs-java8,代码行数:27,代码来源:YamlCollectionCreator.java

示例7: ThreadCommSlave

import java.util.concurrent.LinkedBlockingDeque; //导入依赖的package包/类
/**
 * Process communication constructor, every process have just only one ThreadCommSlave instance.
 * @param loginName if you use ssh to execute command, you must provide login name, e.g. ssh [email protected] "your command"
 * @param threadNum thread number in each process.
 * @param masterHost master host name
 * @param masterPort master host port
 * @throws Mp4jException
 */
public ThreadCommSlave(String loginName, int threadNum, String masterHost, int masterPort) throws Mp4jException {
    this.threadNum = threadNum;
    this.barrier = new CyclicBarrier(threadNum);
    try {
        processCommSlave = new ProcessCommSlave(loginName, masterHost, masterPort);
        this.rank = processCommSlave.getRank();
        this.slaveNum = processCommSlave.getSlaveNum();
        this.threadBQueues = new LinkedBlockingDeque[threadNum];
        for (int t = 0; t < threadNum; t++) {
            this.threadBQueues[t] = new LinkedBlockingDeque<>();
        }
    } catch (Exception e) {
        throw new Mp4jException(e);
    }
}
 
开发者ID:yuantiku,项目名称:ytk-mp4j,代码行数:24,代码来源:ThreadCommSlave.java

示例8: main

import java.util.concurrent.LinkedBlockingDeque; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
     final int maxConsumers = (args.length > 0)
         ? Integer.parseInt(args[0])
         : 5;

     pool = Executors.newCachedThreadPool();
     for (int i = 1; i <= maxConsumers; i += (i+1) >>> 1) {
         // Adjust iterations to limit typical single runs to <= 10 ms;
         // Notably, fair queues get fewer iters.
         // Unbounded queues can legitimately OOME if iterations
         // high enough, but we have a sufficiently low limit here.
         run(new ArrayBlockingQueue<Integer>(100), i, 1000);
         run(new LinkedBlockingQueue<Integer>(100), i, 1000);
         run(new LinkedBlockingDeque<Integer>(100), i, 1000);
         run(new LinkedTransferQueue<Integer>(), i, 700);
         run(new PriorityBlockingQueue<Integer>(), i, 1000);
         run(new SynchronousQueue<Integer>(), i, 300);
         run(new SynchronousQueue<Integer>(true), i, 200);
         run(new ArrayBlockingQueue<Integer>(100, true), i, 100);
     }
     pool.shutdown();
     if (! pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS))
         throw new Error();
     pool = null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:SingleProducerMultipleConsumerLoops.java

示例9: testOfferInExecutor

import java.util.concurrent.LinkedBlockingDeque; //导入依赖的package包/类
/**
 * offer transfers elements across Executor tasks
 */
public void testOfferInExecutor() {
    final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
    q.add(one);
    q.add(two);
    final CheckedBarrier threadsStarted = new CheckedBarrier(2);
    final ExecutorService executor = Executors.newFixedThreadPool(2);
    try (PoolCleaner cleaner = cleaner(executor)) {
        executor.execute(new CheckedRunnable() {
            public void realRun() throws InterruptedException {
                assertFalse(q.offer(three));
                threadsStarted.await();
                assertTrue(q.offer(three, LONG_DELAY_MS, MILLISECONDS));
                assertEquals(0, q.remainingCapacity());
            }});

        executor.execute(new CheckedRunnable() {
            public void realRun() throws InterruptedException {
                threadsStarted.await();
                assertSame(one, q.take());
            }});
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:LinkedBlockingDequeTest.java

示例10: concurrentQueues

import java.util.concurrent.LinkedBlockingDeque; //导入依赖的package包/类
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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:RemovePollRace.java

示例11: instantiateCollectionFromInterface

import java.util.concurrent.LinkedBlockingDeque; //导入依赖的package包/类
private <T> Collection<T> instantiateCollectionFromInterface(Class<? extends T> collectionType) {
    if (List.class.isAssignableFrom(collectionType)) {
        return new ArrayList<T>();
    } else if (SortedSet.class.isAssignableFrom(collectionType)) {
        return new TreeSet<T>();
    } else if (Set.class.isAssignableFrom(collectionType)) {
        return new LinkedHashSet<T>();
    } else if (BlockingDeque.class.isAssignableFrom(collectionType)) {
        return new LinkedBlockingDeque<T>();
    } else if (Deque.class.isAssignableFrom(collectionType)) {
        return new ArrayDeque<T>();
    } else if (BlockingQueue.class.isAssignableFrom(collectionType)) {
        return new LinkedBlockingDeque<T>();
    } else if (Queue.class.isAssignableFrom(collectionType)) {
        return new LinkedList<T>();
    }
    return new ArrayList<T>();
}
 
开发者ID:Yoio,项目名称:X4J,代码行数:19,代码来源:DynamicParsers.java

示例12: testConstructor4

import java.util.concurrent.LinkedBlockingDeque; //导入依赖的package包/类
/**
 * Initializing from Collection of null elements throws NullPointerException
 */
public void testConstructor4() {
    Collection<Integer> elements = Arrays.asList(new Integer[SIZE]);
    try {
        new LinkedBlockingDeque(elements);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:LinkedBlockingDequeTest.java

示例13: testTimedPollLast0

import java.util.concurrent.LinkedBlockingDeque; //导入依赖的package包/类
/**
 * timed pollLast with zero timeout succeeds when non-empty, else times out
 */
public void testTimedPollLast0() throws InterruptedException {
    LinkedBlockingDeque q = populatedDeque(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(SIZE - i - 1, q.pollLast(0, MILLISECONDS));
    }
    assertNull(q.pollLast(0, MILLISECONDS));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:LinkedBlockingDequeTest.java

示例14: testAddAll5

import java.util.concurrent.LinkedBlockingDeque; //导入依赖的package包/类
/**
 * Deque contains all elements, in traversal order, of successful addAll
 */
public void testAddAll5() {
    Integer[] empty = new Integer[0];
    Integer[] ints = new Integer[SIZE];
    for (int i = 0; i < SIZE; ++i)
        ints[i] = new Integer(i);
    LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
    assertFalse(q.addAll(Arrays.asList(empty)));
    assertTrue(q.addAll(Arrays.asList(ints)));
    for (int i = 0; i < SIZE; ++i)
        assertEquals(ints[i], q.poll());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:LinkedBlockingDequeTest.java

示例15: TCPClient

import java.util.concurrent.LinkedBlockingDeque; //导入依赖的package包/类
public TCPClient(String name, TCPResultListener mTCPResultListener){
    this.name = name;
    this.mTCPResultListener = mTCPResultListener;
    mEventBlockDeque = new LinkedBlockingDeque<>();
    mExit = new AtomicBoolean(false);
    mIOThread = new IOThread(name);
}
 
开发者ID:zhenweiyu,项目名称:socket-client-server,代码行数:8,代码来源:TCPClient.java


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