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


Java LinkedTransferQueue类代码示例

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


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

示例1: ZooKeeperCommandExecutor

import java.util.concurrent.LinkedTransferQueue; //导入依赖的package包/类
private ZooKeeperCommandExecutor(String replicaId, CommandExecutor delegate, CuratorFramework curator,
                                 String zkPath, boolean createPathIfNotExist, File revisionFile,
                                 int numWorkers, int maxLogCount, long minLogAgeMillis) {
    super(replicaId);

    this.delegate = delegate;
    this.revisionFile = revisionFile;
    this.curator = curator;
    this.zkPath = zkPath;
    this.createPathIfNotExist = createPathIfNotExist;
    this.maxLogCount = maxLogCount;
    this.minLogAgeMillis = minLogAgeMillis;

    final ThreadPoolExecutor executor = new ThreadPoolExecutor(
            numWorkers, numWorkers,
            60, TimeUnit.SECONDS, new LinkedTransferQueue<>(),
            new DefaultThreadFactory("zookeeper-command-executor", true));
    executor.allowCoreThreadTimeOut(true);
    this.executor = executor;

    logWatcher = new PathChildrenCache(curator, absolutePath(LOG_PATH), true);
    logWatcher.getListenable().addListener(this, MoreExecutors.directExecutor());
    oldLogRemover = new OldLogRemover();
    leaderSelector = new LeaderSelector(curator, absolutePath(LEADER_PATH), oldLogRemover);
    leaderSelector.autoRequeue();
}
 
开发者ID:line,项目名称:centraldogma,代码行数:27,代码来源:ZooKeeperCommandExecutor.java

示例2: concurrentQueues

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

示例3: main

import java.util.concurrent.LinkedTransferQueue; //导入依赖的package包/类
public static void main(String[] args) {
    final Comparator<String> firstChar = new Comparator<>() {
        public int compare(String x, String y) {
            return x.charAt(0) - y.charAt(0); }};

    test(new PriorityQueue<String>(firstChar));
    test(new PriorityQueue<String>(10, firstChar));
    test(new PriorityBlockingQueue<String>(10, firstChar));
    test(new ArrayBlockingQueue<String>(10));
    test(new LinkedBlockingQueue<String>(10));
    test(new LinkedBlockingDeque<String>(10));
    test(new LinkedTransferQueue<String>());
    test(new ArrayDeque<String>(10));

    System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
    if (failed > 0) throw new Error("Some tests failed");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:RemoveContains.java

示例4: main

import java.util.concurrent.LinkedTransferQueue; //导入依赖的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

示例5: main

import java.util.concurrent.LinkedTransferQueue; //导入依赖的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

示例6: concurrentQueues

import java.util.concurrent.LinkedTransferQueue; //导入依赖的package包/类
Collection<Queue<Integer>> concurrentQueues() {
    List<Queue<Integer>> queues = new ArrayList<>();
    queues.add(new ConcurrentLinkedDeque<Integer>());
    queues.add(new ConcurrentLinkedQueue<Integer>());
    queues.add(new ArrayBlockingQueue<Integer>(items, false));
    //queues.add(new ArrayBlockingQueue<Integer>(count, true));
    queues.add(new LinkedBlockingQueue<Integer>());
    queues.add(new LinkedBlockingDeque<Integer>());
    queues.add(new LinkedTransferQueue<Integer>());

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

    // Avoid "first fast, second slow" benchmark effect.
    Collections.shuffle(queues);
    return queues;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:ConcurrentQueueLoops.java

示例7: concurrentQueues

import java.util.concurrent.LinkedTransferQueue; //导入依赖的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

示例8: traversalOperationsCollapseRandomNodes

import java.util.concurrent.LinkedTransferQueue; //导入依赖的package包/类
/**
 * Checks that traversal operations collapse a random pattern of
 * dead nodes as could normally only occur with a race.
 */
@Test(dataProvider = "traversalActions")
public void traversalOperationsCollapseRandomNodes(
    Consumer<LinkedTransferQueue> traversalAction) {
    LinkedTransferQueue q = new LinkedTransferQueue();
    int n = rnd.nextInt(6);
    for (int i = 0; i < n; i++) q.add(i);
    ArrayList nulledOut = new ArrayList();
    for (Object p = head(q); p != null; p = next(p))
        if (rnd.nextBoolean()) {
            nulledOut.add(item(p));
            ITEM.setVolatile(p, null);
        }
    traversalAction.accept(q);
    int c = nodeCount(q);
    assertEquals(q.size(), c - (q.contains(n - 1) ? 0 : 1));
    for (int i = 0; i < n; i++)
        assertTrue(nulledOut.contains(i) ^ q.contains(i));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:WhiteBox.java

示例9: pollActionsOneNodeSlack

import java.util.concurrent.LinkedTransferQueue; //导入依赖的package包/类
@Test(dataProvider = "pollActions")
public void pollActionsOneNodeSlack(
    Consumer<LinkedTransferQueue> pollAction) {
    LinkedTransferQueue q = new LinkedTransferQueue();
    int n = 1 + rnd.nextInt(5);
    for (int i = 0; i < n; i++) q.add(i);
    assertEquals(nodeCount(q), n + 1);
    for (int i = 0; i < n; i++) {
        int c = nodeCount(q);
        boolean slack = item(head(q)) == null;
        if (slack) assertNotNull(item(next(head(q))));
        pollAction.accept(q);
        assertEquals(nodeCount(q), q.isEmpty() ? 1 : c - (slack ? 2 : 0));
    }
    assertInvariants(q);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:WhiteBox.java

示例10: addActionsOneNodeSlack

import java.util.concurrent.LinkedTransferQueue; //导入依赖的package包/类
@Test(dataProvider = "addActions")
public void addActionsOneNodeSlack(
    Consumer<LinkedTransferQueue> addAction) {
    LinkedTransferQueue q = new LinkedTransferQueue();
    int n = 1 + rnd.nextInt(9);
    for (int i = 0; i < n; i++) {
        boolean slack = next(tail(q)) != null;
        addAction.accept(q);
        if (slack)
            assertNull(next(tail(q)));
        else {
            assertNotNull(next(tail(q)));
            assertNull(next(next(tail(q))));
        }
        assertInvariants(q);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:WhiteBox.java

示例11: testConstructor5

import java.util.concurrent.LinkedTransferQueue; //导入依赖的package包/类
/**
 * Queue contains all elements of the collection it is initialized by
 */
public void testConstructor5() {
    Integer[] ints = new Integer[SIZE];
    for (int i = 0; i < SIZE; ++i) {
        ints[i] = i;
    }
    List intList = Arrays.asList(ints);
    LinkedTransferQueue q
        = new LinkedTransferQueue(intList);
    assertEquals(q.size(), intList.size());
    assertEquals(q.toString(), intList.toString());
    assertTrue(Arrays.equals(q.toArray(),
                                 intList.toArray()));
    assertTrue(Arrays.equals(q.toArray(new Object[0]),
                             intList.toArray(new Object[0])));
    assertTrue(Arrays.equals(q.toArray(new Object[SIZE]),
                             intList.toArray(new Object[SIZE])));
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(ints[i], q.poll());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:LinkedTransferQueueTest.java

示例12: testRetainAll

import java.util.concurrent.LinkedTransferQueue; //导入依赖的package包/类
/**
 * retainAll(c) retains only those elements of c and reports true
 * if changed
 */
public void testRetainAll() {
    LinkedTransferQueue q = populatedQueue(SIZE);
    LinkedTransferQueue 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,代码行数:20,代码来源:LinkedTransferQueueTest.java

示例13: testIterator

import java.util.concurrent.LinkedTransferQueue; //导入依赖的package包/类
/**
 * iterator iterates through all elements
 */
public void testIterator() throws InterruptedException {
    LinkedTransferQueue q = populatedQueue(SIZE);
    Iterator it = q.iterator();
    int i;
    for (i = 0; it.hasNext(); i++)
        assertTrue(q.contains(it.next()));
    assertEquals(i, SIZE);
    assertIteratorExhausted(it);

    it = q.iterator();
    for (i = 0; it.hasNext(); i++)
        assertEquals(it.next(), q.take());
    assertEquals(i, SIZE);
    assertIteratorExhausted(it);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:LinkedTransferQueueTest.java

示例14: testIteratorRemove

import java.util.concurrent.LinkedTransferQueue; //导入依赖的package包/类
/**
 * iterator.remove() removes current element
 */
public void testIteratorRemove() {
    final LinkedTransferQueue q = new LinkedTransferQueue();
    q.add(two);
    q.add(one);
    q.add(three);

    Iterator it = q.iterator();
    it.next();
    it.remove();

    it = q.iterator();
    assertSame(it.next(), one);
    assertSame(it.next(), three);
    assertFalse(it.hasNext());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:LinkedTransferQueueTest.java

示例15: testOfferInExecutor

import java.util.concurrent.LinkedTransferQueue; //导入依赖的package包/类
/**
 * offer transfers elements across Executor tasks
 */
public void testOfferInExecutor() {
    final LinkedTransferQueue q = new LinkedTransferQueue();
    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 {
                threadsStarted.await();
                long startTime = System.nanoTime();
                assertTrue(q.offer(one, LONG_DELAY_MS, MILLISECONDS));
                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
            }});

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


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