當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。